# Radio\_button\_tag

**URL:** <https://www.ruby-forum.com/t/radio-button-tag/157137>\
**Category:** Rails\
**Created:** [January 7, 2009, 6:21pm UTC](https://www.ruby-forum.com/t/radio-button-tag/157137 "2009-01-07T18:21:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [January 7, 2009, 6:21pm UTC](https://www.ruby-forum.com/t/radio-button-tag/157137/1 "2009-01-07T18:21:14Z")

</div>

I have an app that needs to collect data on gender, so I have:

Male:  
\<%= radio\_button\_tag( :gender, :male,  
:checked =\> @user.gender.to\_s == ‘Male’ ? true : false,  
:options =\> {:onclick =\> func2} )%\>  
   
Female:  
\<%= radio\_button\_tag( :gender, :female,  
:checked =\> @user.gender.to\_s == ‘Female’ ? true : false,  
:options =\> {:onclick =\> func1} )%\>

I have some remote\_function calling stuff happening in the background,  
everything works great it terms of saving the information, the issue it  
is not showing the corect selected radio button for what is actually  
saved by the user. For example, if the user selects ‘Male’, the app  
shows ‘Female’ as selected. It ‘Female’ is slected it is correct but  
only because it is the last button rendered. What it is doiing is  
setting both buttons checked value to ‘checked’, which it should not be  
doing. I have tried several different way to try and get the correct  
radio button to display as checked, such as:

\<%= radio\_button\_tag( :gender, :male,  
:checked =\> @user.gender.to\_s == ‘Male’ ? ‘checked’ : ‘’,  
:options =\> {:onclick =\> func1} )%\>

This didn’t work either. Anyone know what I am doing wrong. Thanks for  
any and all help?

-S
