Guest wrote:> 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.
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.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---