On Oct 19, 9:56 am, Hakjune Kim <[email protected]> wrote:
> I found from the development log that I'm passing question_single_id as
> nil.
> Seems to be my code of this part is not working
>
> <%= f.fields_for :answer_singles,  {:question_single_id => index} do
> |answer| %>
>     <%= answer.text_area :content, {:question_single_id => index} %>
>
> What I meat to do was to assign question_single_id when I fill the
> answer :content.
> And look up a text_area per each question.
>
> Is there any good solution for text_area and fields_for usage?
>
> I know I'm way far from CRUD development but what to do. (codes are
> getting uglier)
>
> What i should implement is like a quiz system with given questions.
> User login -> answer the given questions -> end
> Admin -> edit questions or review user answers -> end
>

So, with nested_attributes, you're not supposed to iterate over
anything at all -  f.fields_for :answer_singles will iterate over all
the report's AnswerSingle object and yield to the block once for each
one. With this way of thinking if you want one AnswerSingle for each
QuestionSingle then you'd want to do something like this in your
controller

QuestionSingle.each do |qs|
  report.answer_singles.build ...
end

passing to build whatever attributes need to be set on the
answer_single to link it to the question single it corresponds to.

Fred

-- 
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