# Radio buttons - how to identify record using value?

**URL:** <https://www.ruby-forum.com/t/radio-buttons-how-to-identify-record-using-value/132713>\
**Category:** Rails\
**Created:** [March 23, 2008, 10:07pm UTC](https://www.ruby-forum.com/t/radio-buttons-how-to-identify-record-using-value/132713 "2008-03-23T22:07:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![philip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/96bed5/32.png) [@philip](https://www.ruby-forum.com/u/philip)\
**Post date:** [March 23, 2008, 10:07pm UTC](https://www.ruby-forum.com/t/radio-buttons-how-to-identify-record-using-value/132713/1 "2008-03-23T22:07:19Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![philip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/96bed5/32.png) [@philip](https://www.ruby-forum.com/u/philip)\
**Post date:** [March 23, 2008, 11:20pm UTC](https://www.ruby-forum.com/t/radio-buttons-how-to-identify-record-using-value/132713/2 "2008-03-23T23:20:34Z")

</div>

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
