I have a Survey-Response application, where surveys can be created
with an arbitrary number of questions, and users can respond to an
arbitrary number of surveys.
A Survey has_many Questions and has_many Responses. Both a Question
and a Response has_many Answers. That way, everybody has a
relationship to everyone else.
In the Response#new for each Response.survey.questions I do a
@response.answers.build and set the questions_id attribute. That looks
1: survey = Survey.find(params[:survey_id])
2: @response = survey.responses.build
3: @response.survey.questions.each do |question|
4: @response.answers.build(:question_id => question.id)
All I want to do in the form template is get the Answer's Question's
text to display as a label. That looks like this:
6: <% f.fields_for :answers do |fields| %>
7: <p>Q: <%= Question.find(fields[:question_id]).ask %></p>
8: <p>A: <%= fields.text_field :content %><br /></p>
9: <% end %>
Obviously Line 7 is junk, but that's basically what I want to do. How
do I get those prepopulated attribute values? I haven't been able to
find anything on this so it's either obviously staring me in the face
or an odd question.
I found this similar question, but it hasn't received a reply.
Thanks in advance.