سؤال

I have a workout model:

class Workout < ActiveRecord::Base
   attr_accessible :time
   belongs_to :user

   has_and_belongs_to_many :trainers
   accepts_nested_attributes_for :trainers
end

And a trainer model:

class Trainer < ActiveRecord::Base
    attr_accessible :name

    validates_uniqueness_of :name

    has_and_belongs_to_many :workouts

end

I need to have a nester trainer form, which allows to pull values from database. Now I have this inside a new workout form:

 <%= f.fields_for :trainers do |builder| %>
  <%= builder.select :trainer, options_for_select(Trainer.all.collect{ |u| [u.name,     u.id] }) %> 
  <br>
<% end %>

I get "undefined method `trainer' for #"

What am I doing wrong?

هل كانت مفيدة؟

المحلول

I forgot to add attr_accessible :trainers_attributes to Workout controller

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top