# Radio\_button method does not recognize int values?

**URL:** <https://www.ruby-forum.com/t/radio-button-method-does-not-recognize-int-values/89327>\
**Category:** Rails\
**Created:** [January 4, 2006, 8:59am UTC](https://www.ruby-forum.com/t/radio-button-method-does-not-recognize-int-values/89327 "2006-01-04T08:59:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ezran](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b9bd4f/32.png) [@ezran](https://www.ruby-forum.com/u/ezran)\
**Post date:** [January 4, 2006, 8:59am UTC](https://www.ruby-forum.com/t/radio-button-method-does-not-recognize-int-values/89327/1 "2006-01-04T08:59:02Z")

</div>

So the api listing says that radio\_button(object, method, tag\_value,  
options = {}) gives a radio button tag, and if object.method ==  
tag\_value, then the button will be checked.

I verified the method behaves correctly for attributes of type string.  
However, if the attribute is of type int, it doesn’t make the button  
checked.

Does anyone have some information before I file a bug?  
Some tricks to make it work?

Ezra Nugroho

---

<div class="post-metadata">

**Author:** ![ezran](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b9bd4f/32.png) [@ezran](https://www.ruby-forum.com/u/ezran)\
**Post date:** [June 8, 2006, 11:27am UTC](https://www.ruby-forum.com/t/radio-button-method-does-not-recognize-int-values/89327/2 "2006-06-08T11:27:36Z")

</div>

Ezra Nugroho wrote:

> So the api listing says that radio\_button(object, method, tag\_value,  
> options = {}) gives a radio button tag, and if object.method ==  
> tag\_value, then the button will be checked.
> 
> I verified the method behaves correctly for attributes of type string.  
> However, if the attribute is of type int, it doesn’t make the button  
> checked.
> 
> Does anyone have some information before I file a bug?  
> Some tricks to make it work?
> 
> Ezra Nugroho

Ezra,  
I ran into the same problem. But i think i’ve found a solution:

## I have the following table:

Table: accounts  
id :integer  
…  
…  
foo :integer (this is the field with value for the radio  
button)

* * *

edit.rhtml

Here i have the following options, for the user to select:

\<%= radio\_button(“account”,“foo”, “1”) %\>  
\<%= radio\_button(“account”,“foo”, “2”) %\>

* * *

show.rhtml

My show view, shows the data for account with the instance  
variable @account, but to make my Radio-buttons work properly  
(I want the correct radio button to be selected) I had to do  
the following:

\<%= radio\_button(“account”,“foo”,“1”, :disabled =\> true) %\>  
\<%= radio\_button(“account”,“foo”,“2”, :disabled =\> true) %\>

After that the show.rhtml showed the Radio Buttons and the  
the correct Radio Button will be selected, based on the value  
in in the table accounts and attribute foo.

micheldogger

---

<div class="post-metadata">

**Author:** ![ezran](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b9bd4f/32.png) [@ezran](https://www.ruby-forum.com/u/ezran)\
**Post date:** [June 8, 2006, 12:01pm UTC](https://www.ruby-forum.com/t/radio-button-method-does-not-recognize-int-values/89327/3 "2006-06-08T12:01:03Z")

</div>

Plus,

don’t use TINYINT(1) as Datatype in MySQL.  
Rails will return the values as True of False.

micheldogger

---

<div class="post-metadata">

**Author:** ![ezran](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b9bd4f/32.png) [@ezran](https://www.ruby-forum.com/u/ezran)\
**Post date:** [June 8, 2006, 6:12pm UTC](https://www.ruby-forum.com/t/radio-button-method-does-not-recognize-int-values/89327/4 "2006-06-08T18:12:32Z")

</div>

Michel Dogger wrote:

> Plus,
> 
> don’t use TINYINT(1) as Datatype in MySQL.  
> Rails will return the values as True of False.
> 
> micheldogger

Aha! Thanks for comfirming that! I had a lot of trouble figuring that  
one out when I was working through the otherwise-excellent “4 days with  
rails” tutorial!  
Cheers  
Mohit.

---

<div class="post-metadata">

**Author:** ![ezran](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b9bd4f/32.png) [@ezran](https://www.ruby-forum.com/u/ezran)\
**Post date:** [June 8, 2006, 6:45pm UTC](https://www.ruby-forum.com/t/radio-button-method-does-not-recognize-int-values/89327/5 "2006-06-08T18:45:21Z")

</div>

Got it! Thanks guys!
