On Oct 20, 3:32 am, Hakjune Kim <[email protected]> wrote:
>
> def new
> ...
>
>   QuestionSingle.each do |qs|
>     report.answer_singles.build ...
>   end
>
> so answer_single generated as many as questions.
>
> So when I call answer_singles in the fields for it calls every
> answer_singles generated.
>
> <div class="question">
>     <% QuestionSingle.all.each_with_index do |question, index| %>
>       <p><%= index+1 %>. <%= question.content %></p>
>         <%= f.fields_for :answer_singles do |answer| %>
>           <%= answer.text_area :content %>
>           <%= answer.hidden_field :question_single_id, {:value => index}
> %>
>         <% end %>
>     <% end %>
>   </div>

So it's entirely normal that fields_for :answer_singles iterates over
all of them - that's how nested attributes work. If i were you i would
ditch the iteration over QuestionSingle and leave the iteration stuff
to fields_for - when displaying a given answer single I assume that
you're able to locate the corresponding question to display it's
content.


Fred

>
> I have designed models not like report -> question -> answer
> report -> answer (due to the predefined questions by scaffolding)
>
> For all report same questions will be fed and answers have report_id,
> question_id. My question is how I can use answer same as the
> question_id.
>
> Simple fields for shows all answer fields having same report_id.
>
> Let me know if there's better design for predefined questions.
>
> Thanks,
> June
>
> --
> Posted viahttp://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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to