I''ve got a form where I have several items ("packages") listed and I want to query a param that should contain all the "packages" from the form in the controller. However I''m only getting the first item returned. a working example is HATBM checkboxes where <input id="package[names][]" name="package[names][]" type="checkbox" value="z1" /> vs <input id="package_names" name="package[names]" type="text" value="z1" /> how do I get the name="object[method][] here''s the rhtml <%= start_form_tag :action => ''push'' %> <% @packages.each do |p| %> <%= hidden_field ''package'', ''Name'', :value => p.Name %> <% end %> <%= submit_tag "PushIT" %> <%= end_form_tag %> my controller (just a skeleton at the moment to debug def push @params = params @pkgparams = params[:package][:Name] end my result is only the first package from the |p| loop. How do I get multiple text fields to collect into a param with the same name like a checkbox does? thanks -zac -- 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 -~----------~----~----~----~------~----~------~--~---
<%= hidden_field ''package[]'', ''Name'', :value => p.Name %> i guess -- 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 -~----------~----~----~----~------~----~------~--~---
Jean-Etienne Durand wrote:> <%= hidden_field ''package[]'', ''Name'', :value => p.Name %> i guessnope: You have a nil object when you didn''t expect it! You might have expected an instance of ActiveRecord::Base. The error occured while evaluating nil.id_before_type_cast 32: <%= text_field ''package[]'', ''Name'', :value => p.Name %><BR> -- 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 -~----------~----~----~----~------~----~------~--~---
Zac Elston wrote:> I''ve got a form where I have several items ("packages") listed and I > want to query a param that should contain all the "packages" from the > form in the controller. However I''m only getting the first item > returned. > > a working example is HATBM checkboxes where > <input id="package[names][]" name="package[names][]" type="checkbox" > value="z1" /> > vs > <input id="package_names" name="package[names]" type="text" value="z1" > /> > > how do I get the name="object[method][] > > here''s the rhtml > > <%= start_form_tag :action => ''push'' %> > <% @packages.each do |p| %> > <%= hidden_field ''package'', ''Name'', :value => p.Name %> > <% end %> > <%= submit_tag "PushIT" %> > <%= end_form_tag %> > > my controller (just a skeleton at the moment to debug > > def push > > @params = params > @pkgparams = params[:package][:Name] > > end > > my result is only the first package from the |p| loop. > > How do I get multiple text fields to collect into a param with the same > name like a checkbox does?<% @packages.each do |p| %> <%= text_field_tag ''package_names[]'', p.name %> <% end %> params[:package_names] will be an array of strings when the form is posted. -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---