title: Rails radio button: set default value based on model / database entry
body: <p>I'm new to Rails and have been plugging away at this problem without success. I have a form for users to submit answers to multiple choice questions through radio buttons, and I would like their chosen answers to show up again when they revisit the question or on page reload. Their answer is stored in the database, through the TestQuestions model, in an answer_id column. The following code makes the last radio button checked instead of their given answer,  Any suggestions on how to make the default value their answer from the database? </p>
  
  <p>As per my comment below, I think this may require jQuery/javascript to compare the input value in the html ie -</p>
  
  <pre><code>&lt;input id="answer_id_5" type="radio" value ="5" name="answer_id"&gt;&lt;/input&gt; 
  </code></pre>
  
  <p>to the database entry. </p>
  
  <p>show.html.erb</p>
  
  <pre><code>&lt;%= form_tag({controller: "test_questions", action: "update"}, method: "patch") do %&gt;
  
    &lt;% @test_question.question.answers.each do |answer| %&gt;
      &lt;li&gt;
      &lt;%= radio_button_tag "answer_id", answer.id, checked: @test_question.answer_id  %&gt; # THE PROBLEM LINE 
          &lt;%= answer.content %&gt;
      &lt;/li&gt;
    &lt;% end %&gt;
    &lt;%= submit_tag "Next"  %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>test_questions_controller.rb</p>
  
  <pre><code>def show
    @test_question = @test_questions.find(params[:id])
  end
  </code></pre>