I''m trying to pass multiple parameters to the resulting action called by a form. I know you can do: <%= form_tag( { :action => ''search'', :id => params[:id]}, :method => "GET" ) %> To pass the id value, but if I add any more values after this they are ignored, e.g. <%= form_tag( { :action => ''search'', :id => params[:id], :letter => params[:letter]}, :method => "GET" ) %> How do I pass multiple parameters in addition to the id? -- 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 -~----------~----~----~----~------~----~------~--~---
<% form_tag do %> <p> <label for="name">Name:</label> <%= text_field_tag :name, params[:name] %> </p> <p> <label for="password">Password:</label> <%= password_field_tag :password, params[:password] %> </p> <p><%= submit_tag "Login" %></p> <% end %> This sends params[:name] and params[:password] that you can use in your controller. Passing multiple parameters is what a form does. :-) You''re over- thinking it. Also notice that you use <% form_tag ... %> NOT <%= form_tag... %>. No equal sign. You end the form with <% end %>. On Jun 22, 6:10 pm, Richard <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I''m trying to pass multiple parameters to the resulting action called by > a form. > > I know you can do: > > <%= form_tag( { :action => ''search'', :id => params[:id]}, :method => > "GET" ) %> > > To pass the id value, but if I add any more values after this they are > ignored, e.g. > > <%= form_tag( { :action => ''search'', :id => params[:id], :letter => > params[:letter]}, :method => "GET" ) %> > > How do I pass multiple parameters in addition to the id? > > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
Hi Richard, Richard wrote:> > I''m trying to pass multiple parameters to the resulting > action called by a form. > > I know you can do: > > <%= form_tag( { :action => ''search'', :id => params[:id]}, :method => > "GET" ) %> > > To pass the id value, but if I add any more values after this they are > ignored, e.g. > > <%= form_tag( { :action => ''search'', :id => params[:id], :letter => > params[:letter]}, :method => "GET" ) %> > > How do I pass multiple parameters in addition to the id?You''re misunderstanding the syntax. All the values of the fields in your form get passed in the params hash to the action automatically. Set yourself up a sandbox app and experiment to see for yourself. Use params.inspect in the action''s view. hth, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Bill Walton wrote:> Hi Richard, > > Richard wrote: >> ignored, e.g. >> >> <%= form_tag( { :action => ''search'', :id => params[:id], :letter => >> params[:letter]}, :method => "GET" ) %> >> >> How do I pass multiple parameters in addition to the id? > > You''re misunderstanding the syntax. All the values of the fields in > your > form get passed in the params hash to the action automatically. Set > yourself up a sandbox app and experiment to see for yourself. Use > params.inspect in the action''s view. > > hth, > BillI understand that, but I have other parameters that are getting lost. Let me give an example. The user specifies that they want to list all restaurants that match a particular cuisine and begin with a particular letter. The appropriate page of results is then loaded with a select menu at the top of the page which has two options - sort alphabetically, sort by rating (this is my form). When I call this form however it is performing the sort on all of the restaurants. I can make it perform the sort on just the restaurants matching the specific cuisine by using the code I posted above, but any further parameters (such as the specific letter) are not carried over. -- 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 -~----------~----~----~----~------~----~------~--~---
Hi Richard, I''m not sure I''m following. Richard wrote:> I have other parameters that are getting lost. > Let me give an example.It''ll be easier to assist you if you post some additional code, but I''ll give it a shot with what you''ve given us so far. It sounds like you''ve got two forms that get submitted, in sequence, to one or more controller methods. The first form submits two params that are used to retrieve a set of records that are displayed on a page with the second form. It sounds like you''re wanting the second form to submit both the original two params and an additional one (so that the controller can retrieve the same record set that resulted from the first retrieval, but sorted one of two ways). It sounds like the problem you''re having is in rendering the second form so that it will submit all three items as params. Is that right? If so, the easy fix would be to render the first two items as hidden_field items on the second form. Then when the second form gets submitted, the method will have access to all three params. If that''s not helpful, you''ll need to post some additional code for me to help. Or maybe someone else will be able to grok what''s going on better than me and be able to provide better assistance with what you''re already provided. Best regards, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Bill Walton wrote:> If that''s not helpful, you''ll need to post some additional code for me > to > help. Or maybe someone else will be able to grok what''s going on better > than me and be able to provide better assistance with what you''re > already > provided. > > Best regards, > BillThanks Bill. You''re pretty much spot on with what you''ve said. The hidden field thing works fine but I wasn''t sure whether to use it as it puts a lot of stuff in the URL, which kinda looks ugly and maybe a bit revealing of what the code is doing. -- 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 -~----------~----~----~----~------~----~------~--~---
Hi Richard, Richard wrote:> Thanks Bill.You''re very welcome.> You''re pretty much spot on with what you''ve said. The > hidden field thing works fine but I wasn''t sure whether to use it as it > puts a lot of stuff in the URL, which kinda looks ugly and maybe a bit > revealing of what the code is doing.Not 100% sure in this case, but I think you can ''fix'' the URL issues with routes. Best regards, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---