Selectboxes and Rails

Hey was wondering how to setup a select box that when I call
Model.new(params[:model]) it will automatically putit into the db…

I tried

0

then when I do @home = Home.new(params[:home]) that field doesnt insert
into the db… any ideas?

-Ray

Did you remember to execute @home.save afterward?

Ray M. wrote:

Hey was wondering how to setup a select box that when I call
Model.new(params[:model]) it will automatically putit into the db…

I tried

0 ...

then when I do @home = Home.new(params[:home]) that field doesnt insert
into the db… any ideas?

-Ray

Steve K. wrote:

Did you remember to execute @home.save afterward?

Ray M. wrote:

Hey was wondering how to setup a select box that when I call
Model.new(params[:model]) it will automatically putit into the db…

I tried

0 ...

then when I do @home = Home.new(params[:home]) that field doesnt insert
into the db… any ideas?

-Ray

Well it saves all the other information into the database, except for
that one field… the select field.

On 5/30/06, Ray M. [email protected] wrote:

 <option value="0">0</option>

Try changing it to:

And see the magic happen…

Hey Ray,

if the Home attribute is “bedrooms”, as in Home.new().bedrooms, and
you are getting params[:home] then the name attribute of your select
tag should be “home[bedrooms]”.

The rails form helpers will keep you on the right track here:

http://api.rubyonrails.com/classes/ActionView/Helpers/
FormOptionsHelper.html#M000399

as in <%= select :home, :bedrooms, [0,1,2,3,4,5] %>

will create a select box with a name of home[bedrooms] with an option
list from 0 through 5. Although I’ve not tried it you could probably
use a ruby “Range” of (0…5) as well.

Regards,
Trevor

Trevor S.
http://somethinglearned.com