‘公司/新’,然后我得到了以下错误:“未定义的方法`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