I’m making a simple questionnaire app using RoR. I’ve got a model for
Questions, a model for Answers, and a third model, Qa, for matching each
question to five possible answers through foreign keys. So, each qa has
a question and five answers , a1-a5, through belongs_to and a
:foreign_key, and then a selected_answer field for specifying which
answer was selected by the user. The selected_answer is also an Answer
through a foreign key.
Here’s the question: What do I use for the value of the radio button?
I’ve tried the following:
<%= f.radio_button :selected_answer, :a1 %><%= @qa.a1.answer_src %>
<br />
<%= f.radio_button :selected_answer, :a2 %><%= @qa.a2.answer_src %>
<br />
<%= f.radio_button :selected_answer, :a3 %><%= @qa.a3.answer_src %>
<br />
<%= f.radio_button :selected_answer, :a4 %><%= @qa.a4.answer_src %>
<br />
<%= f.radio_button :selected_answer, :a5 %><%= @qa.a5.answer_src %>
</p>
but when I submit the form it errors out with “Answer expected, got
String.” Instead of “:a1”, I’ve also tried “@qa.a1”, with the same
result. How do I use the value of the radio button to signify a record
(object?) without doing something hackish?