# Radio Button Persist

**URL:** <https://www.ruby-forum.com/t/radio-button-persist/75660>\
**Category:** Rails\
**Created:** [November 12, 2006, 12:55am UTC](https://www.ruby-forum.com/t/radio-button-persist/75660 "2006-11-12T00:55:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [November 12, 2006, 12:55am UTC](https://www.ruby-forum.com/t/radio-button-persist/75660/1 "2006-11-12T00:55:15Z")

</div>

Does anyone know how to persist the value of a radio button based on a  
true/false column in the db.

In other words, I have a model with a field called mine (tinyint). My  
radio button s are as follows:

\<%= f.radio\_button :mine, “1”%\> Mine  
\<%= f.radio\_button :mine, “0”, :checked =\> ‘checked’ %\> Friend’s

If there’s an error with the form, the checked attribute takes over, and  
the Mine radio button isn’t checked.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [November 12, 2006, 3:03pm UTC](https://www.ruby-forum.com/t/radio-button-persist/75660/2 "2006-11-12T15:03:53Z")

</div>

Guest wrote:

> the Mine radio button isn’t checked.  
> A MySQL column must be tinyint(1) for Rails to treat it as a Ruby  
> boolean.  
> So you want:

DATABASE:  
mine tinyint(1) not null default 0,

CONTROLLER:  
@model = Model.new(params[:model])

VIEW:  
\<%= f.radio\_button :mine, true %\> Mine  
\<%= f.radio\_button :mine, false %\> Friend’s

–  
We develop, watch us RoR, in numbers too big to ignore.
