Forum: Ruby on Rails radio_button method does not recognize int values?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ezra N. (Guest)
on 2006-01-04 09:59
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
Michel D. (Guest)
on 2006-06-08 13:27
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
Michel D. (Guest)
on 2006-06-08 14:01
Plus,

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

micheldogger
Mohit S. (Guest)
on 2006-06-08 20:12
(Received via mailing list)
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.
Ezra Nugroho (Guest)
on 2006-06-08 20:45
Got it!  Thanks guys!
This topic is locked and can not be replied to.