Giter Site home page Giter Site logo

Comments (9)

alex-quiterio avatar alex-quiterio commented on August 21, 2024

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

from survey.

jakubowiczj avatar jakubowiczj commented on August 21, 2024

@OneDivZero was talking about handle multiple options for one question. At the moment it doesn't work

1d4f603

My form - I'm selecting 2 options for first questions

http://pastie.org/7946700

and in params I should have 2 options but got only one

http://pastie.org/7946690

from survey.

rjst avatar rjst commented on August 21, 2024

Hi jakubowiczj, wel'll look into it and get back to you.

from survey.

kelseymwhelan avatar kelseymwhelan commented on August 21, 2024

Any hotfixes for this issue?

from survey.

rossmckelvie avatar rossmckelvie commented on August 21, 2024

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

from survey.

benjiwheeler avatar benjiwheeler commented on August 21, 2024

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!

from survey.

benjiwheeler avatar benjiwheeler commented on August 21, 2024

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.

from survey.

alex-quiterio avatar alex-quiterio commented on August 21, 2024

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.

from survey.

benjiwheeler avatar benjiwheeler commented on August 21, 2024

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" [email protected]
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 #10 if you
want to look). Thanks for the notice.


Reply to this email directly or view it on GitHubhttps://github.com//issues/5#issuecomment-30053222
.

from survey.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.