# Radio button issues in a list

**URL:** <https://www.ruby-forum.com/t/radio-button-issues-in-a-list/151022>\
**Category:** Rails\
**Created:** [October 16, 2008, 1:01am UTC](https://www.ruby-forum.com/t/radio-button-issues-in-a-list/151022 "2008-10-16T01:01:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tmac26](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/13edae/32.png) [@tmac26](https://www.ruby-forum.com/u/tmac26)\
**Post date:** [October 16, 2008, 1:01am UTC](https://www.ruby-forum.com/t/radio-button-issues-in-a-list/151022/1 "2008-10-16T01:01:20Z")

</div>

Hi,

I have a list of companies for a given user. One (and only one) company  
can be a default company for that user. I have a radio button that  
appears on each row in the list of companies (here is my code):

\<% form\_tag :action =\> ‘update\_default\_company’, :id =\> @company,  
:method =\> :post do %\>

\<% for @company in @companies %\>

  
  
  
 \<% end %\> 

| \<%= "Name" %\> | \<%= "Size" %\> | \<%= "Default Company" %\> |
| --- | --- | --- |
| \<%= @company.name %\> | \<%= @company.size %\> | \<%= radio\_button(“company”, “default\_company”, true) %\> |

 \<%= submit\_tag "Change Default" %\> \<% end %\>

From this list, the user is allowed to change the default company and  
click on a button (implemented with a submit tag, which calls a method  
in the controller). The radio buttons are the only editable field on  
this form.

Question: How do I get the necessary values back to the controller?  
Currently, I only get the selected radio button, but not the associated  
company data.

TIA,

TMac

---

<div class="post-metadata">

**Author:** ![tmac26](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/13edae/32.png) [@tmac26](https://www.ruby-forum.com/u/tmac26)\
**Post date:** [October 16, 2008, 1:43am UTC](https://www.ruby-forum.com/t/radio-button-issues-in-a-list/151022/2 "2008-10-16T01:43:33Z")

</div>

On Oct 16, 12:01 am, Teresa Mcmillin \<rails-mailing-l…@andreas-  
[s.net](http://s.net)\> wrote:

> ```
> <td><%= radio_button("company", "default_company", true) %>
> 
> ```

that third parameter is what will appear in params[:company]  
[:default\_company] so typically you set it to something like  
@company.id.

Overwriting @company like that won’t do you any favours, I would do

\<% for company in @companies %\>  
  
\<%= company.name %\>  
\<%= company.size %\>  
\<%= radio\_button(“company”, “default\_company”, company.id) %\>

\<% end %\>

Fred

---

<div class="post-metadata">

**Author:** ![tmac26](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/13edae/32.png) [@tmac26](https://www.ruby-forum.com/u/tmac26)\
**Post date:** [October 16, 2008, 2:31am UTC](https://www.ruby-forum.com/t/radio-button-issues-in-a-list/151022/3 "2008-10-16T02:31:01Z")

</div>

Frederick C. wrote:

> that third parameter is what will appear in params[:company]  
> [:default\_company] so typically you set it to something like  
> @company.id.
> 
> Overwriting @company like that won’t do you any favours, I would do
> 
> \<% for company in @companies %\>
> 
>   
> \<%= company.name %\>  
> \<%= company.size %\>  
> \<%= radio\_button(“company”, “default\_company”, company.id) %\> \<% end %\>
> 
> Fred

I have changed the third parm and I see what you mean, but here is my  
confusion. I thought the third parm was used for determining which  
radio  
button should be selected, when loading the companies from the database.  
In my case, only one company has default set to true, so I put true in  
the third parm. It works nicely for displaying the data.

So now the question becomes how do I set that radio button values to  
correspond to the database values?

Thanks for your help.

TMac
