Ezra Nugroho
2006-Jan-04 07:59 UTC
[Rails] radio_button method does not recognize int values?
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 -- Posted via http://www.ruby-forum.com/.
Michel Dogger
2006-Jun-08 09:27 UTC
[Rails] Re: radio_button method does not recognize int values?
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 NugrohoEzra, 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 -- Posted via http://www.ruby-forum.com/.
Michel Dogger
2006-Jun-08 10:01 UTC
[Rails] Re: radio_button method does not recognize int values?
Plus, don''t use TINYINT(1) as Datatype in MySQL. Rails will return the values as True of False. micheldogger -- Posted via http://www.ruby-forum.com/.
Mohit Sindhwani
2006-Jun-08 16:09 UTC
[Rails] Re: radio_button method does not recognize int values?
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.