A simple association form gives the "undefined method` klass' for nil: NilClass" error

In my Rails 3 application, I have the following simple relational structure:

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 

Controller:

 def new @rollout = Rollout.new end 

I get the above error with the following form:

 <%= simple_form_for @rollout do |f| %> <%= f.association :items %> <% end %> 
+4
source share
1 answer

There is no connection between Rollout and RolloutItem :

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

The same applies to Item .

+6
source

Source: https://habr.com/ru/post/1481766/


All Articles