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