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 -- Posted via http://www.ruby-forum.com/.
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-- Posted via http://www.ruby-forum.com/.
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? >> >> -RayWell it saves all the other information into the database, except for that one field.. the select field. -- Posted via http://www.ruby-forum.com/.
On 5/30/06, Ray Morgan <RentaRay@yahoo.com> wrote:> 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. >Try changing it to: <select name="home[bedrooms]" id="home_bedrooms"> And see the magic happen.... -- -------------- Jon Gretar Borgthorsson http://www.jongretar.net/
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 On 30-May-06, at 11:05 AM, 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 > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails