Topic: Can't get default "yes" value in form_for select

This should be super simple. I have a contact form with a boolean select that I want to default to yes.

My database defaults the schedule_an_appointment field to 1. I've read that that's enough.

But, just to be sure, in my controller, I have:

  def new
    @contact = Contact.new
    @contact.schedule_an_appointment = 1
  end

(I've also tried setting to true, "Yes", "1" ... )

Even if I add a :select option to my view:

    <%= f.select :schedule_an_appointment, {'Yes' => 1, 'No' => 0}, {:selected => @contact.schedule_an_appointment} %>

Or, explicitly:

    <%= f.select :schedule_an_appointment, {'Yes' => 1, 'No' => 0}, {:selected => 1} %>

Whenever the page loads, I still get "No" as default, and the source shows no option selected.

I'm running Rails 2.3.2 with Passenger.

Any suggestions?

Re: Can't get default "yes" value in form_for select

Could this be an integer vs string thing?  {:selected => "1"}

Rails does a lot of true/false 1/0 conversion for you.  If I were looking at this in my own code, I would consistently use true/false and let ActiveRecord sort out how true/false was stored in the DB.  True/False can remain consistent in the migration (:default => true) and selectors as well (:conditions => {: schedule_an_appointment => true} or :conditions => ["schedule_an_appointment = ?", true]).

Good Luck
mp

Re: Can't get default "yes" value in form_for select

Hm, OK, I'll play around with the values a bit more and see what I get.