Radio buttons - how to identify record using value?

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?

On Sun, 2008-03-23 at 22:07 +0100, Jack’s Brain wrote:

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?


this may be useful…

<TD><input type="radio" id="roles" name="roles[case_manager]"

value=“1” <%= @roles_users[0][‘role_id’] == 1 ? checked=“checked” : ‘’
%> />

<input type=“radio” id=“roles” name=“roles[case_manager]”
value=“2” <%= @roles_users[0][‘role_id’] == 2 ? checked=“checked” : ‘’
%>
<input type=“radio” id=“roles” name=“roles[case_manager]”
value=“3” <%= @roles_users[0][‘role_id’] == 3 ? checked=“checked” : ‘’
%>
<input type=“radio” id=“roles” name=“roles[case_manager]”
value=“4” <%= @roles_users[0][‘role_id’] == 4 ? checked=“checked” : ‘’
%> />

Craig