Closed OneDivZero closed 10 years ago
Hi @OneDivZero I guess that you are not using the new version of the Survey. Currently we just build a new attempt per question, i.e you only see the question once in a form.
Answering to your last question, we just fixed the issue. You are right, we only catch on the controller the first question. The main problem was that every question must have a unique identifier.
<!-- Question 1 has identifier 0 -->
<input id="survey_attempt_answers_attributes_0_option_id"
name="survey_attempt[answers_attributes][0][option_id]" type="checkbox" value="1"/>
<!-- Question 2 has identifier 1 -->
<input id="survey_attempt_answers_attributes_1_option_id"
name="survey_attempt[answers_attributes][1][option_id]" type="checkbox" value="1"/>
Thanks again for the reporting! Doing that help us to improve the Survey gem for everyone! :+1:
@OneDivZero was talking about handle multiple options for one question. At the moment it doesn't work
https://github.com/runtimerevolution/survey/commit/1d4f603b8de779667a23779c33853b9d5ad53357
My form - I'm selecting 2 options for first questions
and in params I should have 2 options but got only one
Hi jakubowiczj, wel'll look into it and get back to you.
Any hotfixes for this issue?
I was able to come up with a workaround that doesn't use the builder and just build out the input tags myself, based on the incorrect markup generated.
<%= form_for [:quizzes, @attempt] do |f| %>
<ul>
<% @assignment.survey.questions.each_with_index do |question, index| %>
<li>
<p><%= question.text %></p>
<input type="hidden" name="survey_attempt[answers_attributes][<%= index %>][question_id]" value="<%= question.id %>" />
<% question.options.each do |option| %>
<input type="checkbox" value="<%= option.id %>" name="survey_attempt[answers_attributes][<%= index %>][option_id]" />
<%= option.text %> <br />
<% end -%>
</li>
<% end -%>
</ul>
<%= f.submit "Submit" %>
<% end -%>
hi, i'm a rails newbie and i'm trying to get survey working. here's where i'm confused: in attempts_controller.rb, in the create function, we make a new attempt with @survey.attempts.new(param[:attempt]). This is confusing to me because when i inspect it in the debugger at this point, param doesn't contain a key called "attempt" -- it does contain "survey_attempt", from alex's fix to issue #5. but the structure of that data doesn't match up with the structure of attempt.rb -- "answers_attributes", etc.
not sure if this has anything to do with it, but the end result is that when i go through the form i've created using the route contests/attempts/new, it allows me to submit and records the attempt itself to the db, but doesn't record any answers.
please stop me if i'm missing something obvious!
Got it working. The crux is an extraneous [] in the name field of check_box_tag in the _form.html.erb. I removed that and made it a radio_button_tag instead and it works fine -- but with no multiple value selection, obviously.
I think the way accepts_nested_attributes_for is used in the model structure of answer, attempt, and option means that the incoming params are expected to have single question ids mapped to single option ids -- not to an array of option ids, which is what the existing _form.html.erb produces.
Hi @brw12, you were right about the parameter key wrongly passed to the attempt object. Your solution with the radio button works, but surveys can have more than one correct answer per question. We are working to fix this, (currently we have a solution in this branch #10 if you want to look). Thanks for the notice.
Thanks for the reply, this is helping me understand both rails and git better!
-Ben 917 254 1578 On Dec 7, 2013 6:42 AM, "Alexandre Quiterio" notifications@github.com wrote:
Hi @brw12 https://github.com/brw12, you were right about the parameter key wrongly passed to the attempt object. Your solution with the radio button works, but surveys can have more than one correct answer per question. We are working to fix this, (currently we have a solution in this branch #10 https://github.com/runtimerevolution/survey/pull/10 if you want to look). Thanks for the notice.
— Reply to this email directly or view it on GitHubhttps://github.com/runtimerevolution/survey/issues/5#issuecomment-30053222 .
Hi again, maybe I do something wrong but currently I can't get the form-partial running. I have a survey with two questions. The new-action in the AttemptsController prepares answers on attempts n-times for each question. However, this causes that all questions will be shown n-times because <%= f.fields_for :answers do |builder| %> renders the ul-tag n-times ?!
Issue 2: Each question has 5 options for answering, but only the last selected option will be in the params-hash. I have to change the checkbox like this: <%= builder.check_box :option_id, {multiple: true}, option.id, nil %>
For what kind of use-case did you provided this form-partial? I think for my case I could never get this working or am I wrong ?