How to display data for nested objects in a check box in Rails? -
i'm having issue want display correct answer in check box in rails, no avail.
the structure further complicated fact models nested 1 survey not has_many, accepts_nested_attributes_for questions , questions has_many choices similarly. problem i'm not able box checked correct answer.
the data saved database boolean in column called correct_choice , code show action shows check boxes, correct choice not checked:
<table class="col-md-10"> <thead> <tr> <% question in @survey.questions %> <li><%= h question.content %></li> <% choice in question.choices %> <li><%= h choice.content %> <%= h check_box(:choice, :correct_choice ) %> <% end %> </li> </li> <% end %> </tr> </thead> </table> i've read documentation, cannot figure out how apply case. can point me in right direction?
edit
this html out:
<table class="col-md-10"> <thead> <tr> <li>is question?</li> <li>i'm not big. i'm having 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 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 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>
i figured out advice @davidwessman. told me display html , inspect. did , compared html edit action (the 1 works).
it became clear needed use check_box_tag command instead of check_box. code use:
<thead> <tr> <% question in @survey.questions %> <li><%= h question.content %></li> <% choice in question.choices %> <li><%= h choice.content %> <%= check_box_tag "correct_choice", "yes", answer.correct_choice %> <% end %> </li> </li> <% end %> </tr> </thead>
Comments
Post a Comment