‘公司/新’,然後我得到了以下錯誤:「未定義的方法`companies_path」錯誤
undefined method `companies_path'
Extracted source (around line #1):
1: <%= form_for(@company) do |f| %>
但是,當我訪問‘公司/ 1 /編輯’(使用相同形式)一切正常。 這是「新」和「編輯」的公司負責人:
def new
@company = Company.new
end
def edit
@company = Company.find(params[:id])
end
這是(的一部分)的形式:
<%= form_for(@company) do |f| %>
<!-- Show errors -->
<%= render('layouts/form_errors', :object => @company) %>
我真的不明白的錯誤消息,因爲'companies_path'沒有被用在代碼中?
更新:這裏是routes.rb中:
get "users_dashboard/show"
get "login" => "sessions#new", :as => "login"
get "logout" => "sessions#destroy", :as => "logout"
resources :company
resources :relations
resources :activities
resources :contacts
resources :notes
resources :tasks
resources :users
resources :sessions
get "site/index"
get "site/features"
get "site/dashboard"
root :to => 'users_dashboard#show'
這裏是公司的模式:
class Company < ActiveRecord::Base
has_many :users
has_many :relations
has_many :contacts, :through => :relations
has_many :notes, :through => :contacts
has_many :tasks, :through => :contacts
has_one :subscription
accepts_nested_attributes_for :subscription
attr_accessible :name, :address1, :address2, :zipcode, :city, :country, :email, :website, :telephone, :twitter, :linkedin, :code
validates :name, :address1, :zipcode, :city, :country, :code, presence: true
validates_length_of :code, :maximum => 3
末
請發表您的config/routes.rb文件 – lucapette
routes.rb中添加 – John
模型公司加入 – John