Wednesday, October 19, 2011

[Rails] Re: [Beginner] fields_for within each loop

By making it nested_attributes I'm able to control it but still some
weird loop.
I don't fully understand how loop works in rails so please advise.

First this code makes one text area per each question.
<div class="question">
<% QuestionSingle.all.each_with_index do |question, index| %>
<p><%= index+1 %>. <%= question.content %></p>
<%= f.fields_for :answer_singles, {:question_id => :index} do
|answer| %>
<%= answer.text_area :content %>
<% end %>
<% end %>
</div>

After I put answers and edit it makes number of answer text area same as
questions.

Please let me know how I can make the text area per question.

Thank you and regards,
June

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate