I'm building a survey app and part of that app has two models:
#ResponseSet
has_many :responses
accepts_nested_attributes_for :responses
#Response
belongs_to :response_set
belongs_to :answer
As an example, you might have a survey with a multiple choice question where you can select multiple answers (What types of pets do you have? Dog, cat, horse).
What is supposed to happen is that when you submit your answers for a survey, a record is added to the Response table for each answer. So if you selected that you had a dog, cat and horse, 3 records would be added, each one referencing the Answer model via :answer_id.
I can do it for questions with one answer, but ones with multiple answers is breaking my brain.
It gets more complicated because in a single survey there could be multiple questions each with multiple answers.
For reference, current form field names look like this:
response_set[responses_attributes][0][answer_id]
response_set[responses_attributes][1][answer_id]
response_set[responses_attributes][2][answer_id]
Generated by this:
<%= form_for @response_set, :url => complete_survey_path do |f| %>
<%= f.fields_for :responses do |response| %>
<%= response.check_box :answer_id %>
<% end %>
<% end %>
So that'd be the field for answer_id in the response_attributes for 3 different questions.
1234is theidof your answer,response_set[responses_attributes][0][1234][answer_id]looks a lot likeresponse_set[responses_attributes][0][answer_id][answer_id]. That doesn't look right to me.