Forum: Ruby on Rails Selectboxes and Rails

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B80e1f4fdf39c57f89afadfa7d297f9d?d=identicon&s=25 Ray Morgan (Guest)
on 2006-05-30 20:05
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
<select name="home_bedrooms" id="home_bedrooms">
	<option value="0">0</option>
        ...
</select>

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

-Ray
34f5b045aec62235c17458650ea75353?d=identicon&s=25 Steve Koppelman (hatless)
on 2006-05-30 20:15
Did you remember to execute @home.save afterward?


Ray Morgan 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
> <select name="home_bedrooms" id="home_bedrooms">
> 	<option value="0">0</option>
>         ...
> </select>
>
> then when I do @home = Home.new(params[:home]) that field doesnt insert
> into the db.. any ideas?
>
> -Ray
B80e1f4fdf39c57f89afadfa7d297f9d?d=identicon&s=25 Ray Morgan (Guest)
on 2006-05-30 20:31
Steve Koppelman wrote:
> Did you remember to execute @home.save afterward?
>
>
> Ray Morgan 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
>> <select name="home_bedrooms" id="home_bedrooms">
>> 	<option value="0">0</option>
>>         ...
>> </select>
>>
>> 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.
30ee518e6fdc5b07e060775b5a542bdb?d=identicon&s=25 Jón Borgþórsson (jongretar)
on 2006-05-30 20:42
(Received via mailing list)
On 5/30/06, Ray Morgan <RentaRay@yahoo.com> wrote:
> >>      <option value="0">0</option>
>
Try changing it to:
    <select name="home[bedrooms]" id="home_bedrooms">
And see the magic happen....

--
27c170f482104299af279902be0a9c26?d=identicon&s=25 Trevor Squires (Guest)
on 2006-05-30 20:54
(Received via mailing list)
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 Squires
http://somethinglearned.com
This topic is locked and can not be replied to.