我不明白为什么我会得到这个错误
undefined method `sector_id' for #<Portfolio:0x007fe17c2e3848>
我有一个投资组合模型和一个行业模型,它们看起来是这样的
class Portfolio < ActiveRecord::Base
belongs_to :sector
attr_accessible :overview, :title, :sector_id
end
class Sector < ActiveRecord::Base
has_many :portfolios
attr_accessible :name
end
我的路线
resources :portfolios do
resources :sectors
end
所以在我的表单中,为了创建一个新的项目组合,我有这个collection_select
<%= f.label :sector_id, "Choose Sector", :class => 'title_label' %><br>
<%= f.collection_select(:sector_id, Sector.all, :id, :name, :prompt => "Please Select a Sector") %>
这是我以前做过很多次的事情,它起作用了,有人能看到为什么我会得到这个错误吗?
我能想到的唯一一件事是,我将投资组合的控制器称为投资组合,我总是与复数和单数控制器名称混淆,这对我的情况会有影响吗?
https://stackoverflow.com/questions/18056809
复制相似问题