simple-form association为nil提供了“未定义的方法`klass”:NilClass“错误

时间:2013-05-20 14:13:55

标签: ruby-on-rails-3 simple-form

在我的Rails 3应用程序中,我有以下简单的关系结构:

class Rollout < ActiveRecord::Base
    has_many :items, :through => :rollout_items
end

class RolloutItem < ActiveRecord::Base
    belongs_to :rollout
    belongs_to :item
end

class Item < ActiveRecord::Base
    has_many :rollouts, :through => :rollout_items
end

控制器:

def new
    @rollout = Rollout.new
end

我使用以下格式获得上述错误:

<%= simple_form_for @rollout do |f| %>
    <%= f.association :items %>
<% end %>

1 个答案:

答案 0 :(得分:6)

RolloutRolloutItem之间缺少关系:

class Rollout < ActiveRecord::Base
    has_many :rollout_items # This.
    has_many :items, :through => :rollout_items
end

Item同样如此。

相关问题