문제

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