I''m working with a form where only entries in the text fields are being saved to the database. The options selected from the select lists are not. Not sure what I need to do. Just to show how things are set up in the controller: def post @position = Position.new(params[:position]) @position.save end Then in the view I''ll show one text field and one select: <%= form_tag :action => ''post'' %> #text field <%= text_field(:position, :title) %> #select <%= collection_select(:state, liststates, @states, :id, :name, { :include_blank => true } ) %> The method liststates is in the helper to gather up the options from the table. The intention is to save the state id to the positions table in the column state_id. I''m gathering that the select statements need something else. Hope it''s okay to ask while I dig around. TIA Stuart --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Stuart Fellowes wrote:> I''m working with a form where only entries in the text fields are > being saved to the database. The options selected from the select > lists are not. Not sure what I need to do. > > Just to show how things are set up in the controller: > def post > @position = Position.new(params[:position]) > @position.save > end > > Then in the view I''ll show one text field and one select: > <%= form_tag :action => ''post'' %> > #text field > <%= text_field(:position, :title) %> > #select > <%= collection_select(:state, liststates, @states, :id, :name, { > :include_blank => true } ) %>collection_select is like all the other similar helpers( such as text_field) in that if you give it as the first 2 parameters foo and bar then in the HTML the parameter name is foo[bar], and when the request is submitter you end up with params[:foo] containing all the parameters for foo. Here you are passing :state as the object name, and so in the post action those settings are found inside params[:state], Fred -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Thanks Fred, just had figured out what I need to do, as it''s now working in one field (one corrected) Prior - I had a helper that had a bunch of methods such as: def liststates @states = State.find(:all, :order => "name") end So in my collection select I had to call the method liststates. Now I tried just throwing @states = State.find(:all, :order => "name") in the helper but get a nil error when i called up the form. So I moved it to the controller action and then <%= collection_select(:position, :state_id , @states, :id, :name, ........ with position being the model and state_id the method to update the table. So I guess I"m good to go. Stuart On 9/16/06, Fred <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Stuart Fellowes wrote: > > I''m working with a form where only entries in the text fields are > > being saved to the database. The options selected from the select > > lists are not. Not sure what I need to do. > > > > Just to show how things are set up in the controller: > > def post > > @position = Position.new(params[:position]) > > @position.save > > end > > > > Then in the view I''ll show one text field and one select: > > <%= form_tag :action => ''post'' %> > > #text field > > <%= text_field(:position, :title) %> > > #select > > <%= collection_select(:state, liststates, @states, :id, :name, { > > :include_blank => true } ) %> > > collection_select is like all the other similar helpers( such as > text_field) in that if you give it as the first 2 parameters foo and > bar then in the HTML the parameter name is foo[bar], and when the > request is submitter you end up with params[:foo] containing all the > parameters for foo. > > Here you are passing :state as the object name, and so in the post > action those settings are found inside params[:state], > > Fred > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---