I'm having this issue where I want to display the correct answer in a check box in Rails, to no avail.
The structure is further complicated by the fact that my models are nested into one another so that Survey not only has_many, but also accepts_nested_attributes_for Questions and Questions has_many Choices similarly. The problem is that I'm simply not able to get the box checked for the correct answer.
The data are saved to the database as a boolean in a column called correct_choice and this code for the show action shows the check boxes, but the correct choice is not checked:
<table class="col-md-10">
<thead>
<tr>
<% for question in @survey.questions do %>
<li><%= h question.content %></li>
<% for choice in question.choices do %>
<li><%= h choice.content %>
<%= h check_box(:choice, :correct_choice ) %>
<% end %>
</li>
</li>
<% end %>
</tr>
</thead>
</table>
I've read the documentation, but I cannot figure out how to apply it to my case. Can anybody point me in the right direction?
EDIT
This is the HTML that I get out:
<table class="col-md-10">
<thead>
<tr>
<li>Is this a question?</li>
<li>I'm not big. I'm having a breakdown.
<input name="correct_choice[content]" type="hidden" value="0" /><input type="checkbox" value="1" name="correct_choice[content]" id="correct_answer_content" />
<li>Come on, I'm not big.
<input name="correct_choice[content]" type="hidden" value="0" /><input type="checkbox" value="1" name="correct_choice[content]" id="correct_choice_content" />
<li>Who is hungry?
<input name="correct_choice[content]" type="hidden" value="0" /><input type="checkbox" value="1" name="correct_choice[content]" id="correct_choice_content" />
<li>Pass the cheese, please.
<input name="correct_choice[content]" type="hidden" value="0" /><input type="checkbox" value="1" name="correct_choice[content]" id="correct_choice_content" />
</li>
</li>
</tr>
</thead>
</table>