f.fields_for a has_many relationship in rails -


i have assessment model has_many answers. i'm trying build f.fields_for getting error:

"undefined method `content' <answer::activerecord_associations_collectionproxy:0x007fdb12041fd8>" 

view:

 <%= f.fields_for @answers |builder| %>    <%= builder.text_area :content, :class=>"form-control question-field", :data => {:question => question.id} %>   <% end %> 

controller:

  def edit     @assessment = current_user.assessments.find(params[:id])     @answers = @assessment.answers   end 

i understand error seems i'm calling methods on collection rather individual object. don't understand how fix it.

if f builder @assassment, can do:

<%= f.fields_for :answers |builder| %>   <%= builder.text_area :content, :class=>"form-control question-field", :data => {:question => question.id} %> <% end %> 

you need in assassement model:

class assasement < activerecord::base   has_many :answers   accepts_nested_attributes_for :answers   #... end 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -