Consider the following: -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Consider the following: - - - <% form_for @countryToSearchFor, :url => signed_in_path(:action => "show", :id => ''connected_to_country'', :something => ''other''), :html => {:method => :get} do |f| %> <%= f.select :country, language_neutral_array_of_countries, :prompt => ''enter_country'' %> <div> <%= f.submit shnI18n.literal(''search_for_connection'') %> </div> <% end %> - - - The debugger tells me that signed_in_path(:action => "show", :id => ''connected_to_country'', :something => ''other'') # ==> "/signed_in/connected_to_country?locale=en&something=other" When the user submits the form both the parameters (locale and something) have disappeared. This causes more than a small bit of havoc. How can I pass parameters via a submit to a controller via params? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 6 March 2010 18:50, Ralph Shnelvar <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Consider the following: > > - - - > <% form_for @countryToSearchFor, :url => signed_in_path(:action => > "show", > :id => ''connected_to_country'', :something => ''other''), > :html => {:method => :get} do |f| %> > > <%= f.select :country, language_neutral_array_of_countries, > :prompt => ''enter_country'' %> > <div> > <%= f.submit shnI18n.literal(''search_for_connection'') %> > </div> > <% end %> > - - - > > The debugger tells me that > signed_in_path(:action => "show", > :id => ''connected_to_country'', :something => ''other'') > # ==> "/signed_in/connected_to_country?locale=en&something=other" > > When the user submits the form both the parameters (locale and > something) have disappeared. This causes more than a small bit of > havoc.I think maybe you cannot include query terms in form_for :url. An alternative is to use hidden fields in the form. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ralph Shnelvar
2010-Mar-07 11:00 UTC
Re: Re: form_for, submit, and parameters disappearing
Colin Law wrote:> I think maybe you cannot include query terms in form_for :url. An > alternative is to use hidden fields in the form.Colin, thank you. You appear to be correct. So for the next poor person fighting to get internationalization to work (I18n. See http://guides.rubyonrails.org/i18n.html Section 2.3 Setting and Passing the Locale) .. form_for cannot be, uh, "internationalized" because the various flavors of url_for that I18n hooks will have the locale parameter disappear if a form, any form, is used. It appears not to be an ruby/rails/I18n problem but an arcane "problem" in html. Thus ... if you want to pass a couple of extra parameters when using form_for ... you can do what I did. I''m pasting in my adlterated code: - - - - - - - <% form_for @countryToSearchFor, :url => signed_in_path(:action => "show", :id => ''connected_to_country''), :html => {:method => :get} do |f| %> <input type="hidden" name="locale" value="<%= params[:locale] %>" > <input type="hidden" name="somename" value="someothervalue" > <%= f.select :country, language_neutral_array_of_countries, :prompt => shnI18n.literal(''enter_country'') %> <br /> <br /> <div> <%= f.submit shnI18n.literal(''search_for_connection'') %> </div> <% end %> - - - - - - - You will note the <input type="hidden" name="locale" value="<%= params[:locale] %>" > <input type="hidden" name="somename" value="someothervalue" > The first <input> is the critical one where the locale is being passed. The second <input> simply shows how to pass :somename => "someothervalue". Both parameters (locale, somename) will end up in the params received by the relevant controller. - - - I find using raw html to be far far easier to understand and more convenient to use than the hidden_field api documented in http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html. - - - I find it amusing that the spam filter does not like the (proper spelling of) the word "adlterated" -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 7 March 2010 11:00, Ralph Shnelvar <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote: >> I think maybe you cannot include query terms in form_for :url. An >> alternative is to use hidden fields in the form. > > Colin, thank you. You appear to be correct. > > So for the next poor person fighting to get internationalization to work > (I18n. See http://guides.rubyonrails.org/i18n.html Section 2.3 Setting > and Passing the Locale) .. > > form_for cannot be, uh, "internationalized" because the various flavors > of url_for that I18n hooks will have the locale parameter disappear if a > form, any form, is used. It appears not to be an ruby/rails/I18n problem > but an arcane "problem" in html. > > Thus ... if you want to pass a couple of extra parameters when using > form_for ... you can do what I did. I''m pasting in my adlterated code: > > - - - - - - - > <% form_for @countryToSearchFor, > :url => signed_in_path(:action => "show", :id => > ''connected_to_country''), > :html => {:method => :get} do |f| %> > <input type="hidden" name="locale" value="<%= params[:locale] %>" > > <input type="hidden" name="somename" value="someothervalue" > > <%= f.select :country, > language_neutral_array_of_countries, > :prompt => shnI18n.literal(''enter_country'') %> > <br /> > <br /> > <div> > <%= f.submit shnI18n.literal(''search_for_connection'') %> > </div> > <% end %> > - - - - - - - > > You will note the > <input type="hidden" name="locale" value="<%= params[:locale] %>" > > <input type="hidden" name="somename" value="someothervalue" > > > The first <input> is the critical one where the locale is being passed. > The second <input> simply shows how to pass :somename => > "someothervalue". > > Both parameters (locale, somename) will end up in the params received by > the relevant controller. > > - - - > > I find using raw html to be far far easier to understand and more > convenient to use than the hidden_field api documented in > http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html.What is wrong with <%= hidden_field_tag "locale", params[:locale] %> Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ralph Shnelvar
2010-Mar-07 14:14 UTC
Re: Re: Re: form_for, submit, and parameters disappearing
Colin Law wrote:> On 7 March 2010 11:00, Ralph Shnelvar <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> form_for cannot be, uh, "internationalized" because the various flavors >> ''connected_to_country''), >> �</div> >> >> Both parameters (locale, somename) will end up in the params received by >> the relevant controller. >> >> - - - >> >> I find using raw html to be far far easier to understand and more >> convenient to use than the hidden_field api documented in >> http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html. > > What is wrong with > <%= hidden_field_tag "locale", params[:locale] %> > > ColinI was going to argue the point, Colin, but, yeah, that works. It''s always nice to have an additional level of indirection. So ... thanks again. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Mar-09 17:42 UTC
Re: Re: form_for, submit, and parameters disappearing
Ralph Shnelvar wrote:> Colin Law wrote: >> I think maybe you cannot include query terms in form_for :url. An >> alternative is to use hidden fields in the form. > > Colin, thank you. You appear to be correct. > > So for the next poor person fighting to get internationalization to work > (I18n. See http://guides.rubyonrails.org/i18n.html Section 2.3 Setting > and Passing the Locale) .. > > form_for cannot be, uh, "internationalized" because the various flavors > of url_for that I18n hooks will have the locale parameter disappear if a > form, any form, is used. It appears not to be an ruby/rails/I18n problem > but an arcane "problem" in html. > > Thus ... if you want to pass a couple of extra parameters when using > form_for ... you can do what I did. I''m pasting in my adlterated code: > > - - - - - - - > <% form_for @countryToSearchFor, > :url => signed_in_path(:action => "show", :id => > ''connected_to_country''), > :html => {:method => :get} do |f| %> > <input type="hidden" name="locale" value="<%= params[:locale] %>" > > <input type="hidden" name="somename" value="someothervalue" >[...] Why not store the locale in the session, instead of passing around hidden fields? Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ralph Shnelvar
2010-Mar-13 23:55 UTC
Re: Re: form_for, submit, and parameters disappearing
Marnen Laibow-Koser wrote:> Why not store the locale in the session, instead of passing around > hidden fields?From http://guides.rubyonrails.org/i18n.html - - - - You may be tempted to store the chosen locale in a session or a cookie. Do not do so. The locale should be transparent and a part of the URL. This way you don’t break people’s basic assumptions about the web itself: if you send a URL of some page to a friend, she should see the same page, same content. - - - - -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.