I feel really stupid spending over 24 hours trying to figure out 1 line of code but I still can''t get it. I have a table addpackages, that I want to update multiple fields from table rosters based on the selection of a drop down. In addpackage.rb: def create @addpackage = Addpackage.new(@params["add"]) In new.rhtml (view): <select name="add[email]"> <%=options_from_collection_for_select(@rosters, "email", "lname", selected_value = nil)%> This code works perfect for obtaining the correct email address based on drop down and updating the addpackages table. I could replace "email" with "fname", "lname", etc etc and it would work fine also. Whats killing me is I can only get one parameter to pass and update. I cannot for the life of me figure out how to pass email, fname, and lname based on the selected drop down. Help!!!!!!!!!!!!!!!!!!! -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
Wai Tsang
2007-Apr-23 17:36 UTC
Re: Spent over 24 hours trying to figure this - multiple par
Tony M. wrote:> I feel really stupid spending over 24 hours trying to figure out 1 line > of code but I still can''t get it. > > I have a table addpackages, that I want to update multiple fields from > table rosters based on the selection of a drop down. > > > In addpackage.rb: > def create > @addpackage = Addpackage.new(@params["add"]) > > > In new.rhtml (view): > <select name="add[email]"> > <%=options_from_collection_for_select(@rosters, "email", "lname", > selected_value = nil)%> > > > > This code works perfect for obtaining the correct email address based on > drop down and updating the addpackages table. I could replace "email" > with "fname", "lname", etc etc and it would work fine also. Whats > killing me is I can only get one parameter to pass and update. I > cannot for the life of me figure out how to pass email, fname, and lname > based on the selected drop down. > > > Help!!!!!!!!!!!!!!!!!!!You would need to use param_name[] if you want to be able to read an array of parameters instead of just the one value. For example, <% choices = options_from_collection_for_select(@rosters, :id, :email, nil) -%> <%= select_tag("email_ids[]", choices, {:multiple => true, :size => 10}) -%> -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom
2007-Apr-23 17:49 UTC
Re: Spent over 24 hours trying to figure this - multiple params
> I feel really stupid spending over 24 hours trying to figure out 1 line > of code but I still can''t get it. > > I have a table addpackages, that I want to update multiple fields from > table rosters based on the selection of a drop down. > > > In addpackage.rb: > def create > @addpackage = Addpackage.new(@params["add"]) > > > In new.rhtml (view): > <select name="add[email]"> > <%=options_from_collection_for_select(@rosters, "email", "lname", > selected_value = nil)%> > > > > This code works perfect for obtaining the correct email address based on > drop down and updating the addpackages table. I could replace "email" > with "fname", "lname", etc etc and it would work fine also. Whats > killing me is I can only get one parameter to pass and update. I > cannot for the life of me figure out how to pass email, fname, and lname > based on the selected drop down.Don''t. Pass the primary key (ie. ''id'') in the <select> and then your controller look up that roster entry and now you have access to everything you want. -philip --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Tony M.
2007-Apr-23 17:50 UTC
Re: Spent over 24 hours trying to figure this - multiple par
Philip Hallstrom wrote:>> >> with "fname", "lname", etc etc and it would work fine also. Whats >> killing me is I can only get one parameter to pass and update. I >> cannot for the life of me figure out how to pass email, fname, and lname >> based on the selected drop down. > > Don''t. Pass the primary key (ie. ''id'') in the <select> and then your > controller look up that roster entry and now you have access to > everything > you want. > > -philipOkay I made the folling changes to view: <select name="add[id]"> <%=options_from_collection_for_select(@rosters, "id", "lname", selected_value = nil)%> Now in my controller can you give an example of how to set: roster.fname = addpackage.fname (I know my syntax is incorrect) Thanks very much for your help, much appreciated. This is my first time with RoR. -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom
2007-Apr-23 18:15 UTC
Re: Spent over 24 hours trying to figure this - multiple par
>>> >>> with "fname", "lname", etc etc and it would work fine also. Whats >>> killing me is I can only get one parameter to pass and update. I >>> cannot for the life of me figure out how to pass email, fname, and lname >>> based on the selected drop down. >> >> Don''t. Pass the primary key (ie. ''id'') in the <select> and then your >> controller look up that roster entry and now you have access to >> everything >> you want. >> >> -philip > > Okay I made the folling changes to view: > <select name="add[id]"> > <%=options_from_collection_for_select(@rosters, "id", "lname", > selected_value = nil)%> > > > > Now in my controller can you give an example of how to set: > roster.fname = addpackage.fname (I know my syntax is incorrect)Dn''t you mean the other way? I think you do... so... p = Package.new r = Roster.find_by_id(params[:add][:id]) p.fname = r.fname ....> > > Thanks very much for your help, much appreciated. This is my first time > with RoR. > > -- > 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?hl=en -~----------~----~----~----~------~----~------~--~---
Tony M.
2007-Apr-24 02:03 UTC
Re: Spent over 24 hours trying to figure this - multiple par
Philip Hallstrom wrote:>>> >> roster.fname = addpackage.fname (I know my syntax is incorrect) > Dn''t you mean the other way? I think you do... so... > > p = Package.new > r = Roster.find_by_id(params[:add][:id]) > p.fname = r.fname > > ....Thank you! Your help was very much appreciated. And yes you were correct I typed it backwards. -- 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?hl=en -~----------~----~----~----~------~----~------~--~---