title: Rails quiz app getting results
body: <p>I'm trying to make a rails quiz application and am having a problem.
  I'm using the nested_forms gem and I can normally create quizzes.
  Here is the code for creating quizzes:</p>
  
  <p>_form.html.erb:</p>
  
  <pre><code>&lt;%= nested_form_for @quiz do |f| %&gt;
  
      &lt;%= f.text_field :name %&gt;
  
      &lt;%= f.fields_for :questions do |question_form| %&gt;
  
          &lt;h5&gt;Question&lt;/h5&gt;
  
              &lt;%= question_form.text_field :question %&gt;
  
              &lt;%= question_form.text_field :option1 %&gt;
  
              &lt;%= question_form.radio_button :trueoption, 1 %&gt;
  
              &lt;%= question_form.text_field :option2 %&gt;
  
              &lt;%= question_form.radio_button :trueoption, 2 %&gt;
  
              &lt;%= question_form.text_field :option3 %&gt;
  
              &lt;%= question_form.radio_button :trueoption, 3 %&gt;
  
              &lt;%= question_form.link_to_remove "Remove" %&gt;
      &lt;% end %&gt;
  
  
          &lt;%= f.link_to_add "Add a question", :questions %&gt;
  
          &lt;%= f.submit "I'm Done!", class: "button" %&gt;
  
  &lt;% end %&gt;
  </code></pre>
  
  <p>This works perfectly, the quiz is created and saved.
  But then when trying to solve the quiz the problems occur.
  When I go on a show view of a quiz (like quizzes/8) I'm showing the quiz normally with this:</p>
  
  <pre><code>            &lt;%= nested_form_for @result do |f| %&gt;
  
                      &lt;% @quiz.questions.each do |question| %&gt;
                          &lt;%= f.fields_for question do |q| %&gt;
                              &lt;div class="panel"&gt;
  
                                  &lt;h2&gt;&lt;%= question.question %&gt;&lt;/h2&gt;
                                  &lt;h5&gt;&lt;%= q.radio_button :trueoption, 1, id: question.id %&gt;&lt;%= label :trueoption_option1, question.id %&gt;&lt;/h5&gt;
                                  &lt;h5&gt;&lt;%= q.radio_button :trueoption, 2, id: question.id %&gt;&lt;%= label :trueoption_option2, question.id %&gt;&lt;/h5&gt;
                                  &lt;h5&gt;&lt;%= q.radio_button :trueoption, 3, id: question.id %&gt;&lt;%= label :trueoption_option3, question.id %&gt;&lt;/h5&gt;
  
  
                              &lt;/div&gt;
                          &lt;% end %&gt;
                      &lt;% end %&gt;
              &lt;%= f.submit %&gt;
          &lt;% end %&gt;
  </code></pre>
  
  <p>And it shows each question normally, like it should. But what doesn't work are the radio buttons; it's like they are all the same, only 1 can be checked out of all. What is the problem?</p>
  
  <p>Here are the controllers:</p>
  
  <p>quizzes_controller.rb:</p>
  
  <pre><code>class QuizzesController &lt; ApplicationController
  def index
    @quizzes = Quiz.all
  end
  
  def new
    @quiz = Quiz.new
    3.times do
      question = @quiz.questions.build
    end
  end
  
  def create
    @quiz = Quiz.create(params[:quiz])
    if @quiz.save
      redirect_to @quiz
    else
      render :action =&gt; :new
    end
  end
  
  def show
    @quiz = Quiz.find(params[:id])
    @result = Result.new
  end
  end
  </code></pre>
  
  <p>Results controller:</p>
  
  <pre><code>class ResultsController &lt; ApplicationController
  def new
    @result = Result.new
  end
  
  def create
    @result = Result.create(params[:result])
  
    if @result.save
      redirect_to @result
    else
      render action: :new
    end
  end
  
  def show
    @result = Result.find(params[:id])
  end
  end
  </code></pre>
  
  <p>And the models:</p>
  
  <p>Quiz.rb</p>
  
  <pre><code>class Quiz &lt; ActiveRecord::Base
    attr_accessible :name, :questions_attributes
  
    has_many :questions
  
    accepts_nested_attributes_for :questions, allow_destroy: true
  end
  </code></pre>
  
  <p>Question.rb</p>
  
  <pre><code>class Question &lt; ActiveRecord::Base
    attr_accessible :option1, :option2, :option3, :trueoption, :quiz_id, :question
  
    belongs_to :quiz
    has_many :answers
  end
  </code></pre>
  
  <p>Result.rb</p>
  
  <pre><code>class Result &lt; ActiveRecord::Base
    attr_accessible :question_id, :trueoption, :question_attributes
  
    belongs_to :question
  
    accepts_nested_attributes_for :question
  end
  </code></pre>
  
  <p>So basically, what it does is it saves only 1 result instead of each one seperately (nested form), but it should save a result for each question specifically.</p>
  
  <p>Thanks in advance</p>