4

在我的 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 %>
4

1 回答 1

6

Rollout和之间缺少关系RolloutItem

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

也是如此Item

于 2013-05-20T14:48:01.330 回答