# Form\_for, submit, and parameters disappearing

**URL:** <https://www.ruby-forum.com/t/form-for-submit-and-parameters-disappearing/184688>\
**Category:** Rails\
**Created:** [March 6, 2010, 7:36pm UTC](https://www.ruby-forum.com/t/form-for-submit-and-parameters-disappearing/184688 "2010-03-06T19:36:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [March 6, 2010, 7:36pm UTC](https://www.ruby-forum.com/t/form-for-submit-and-parameters-disappearing/184688/1 "2010-03-06T19:36:35Z")

</div>

Consider the following:

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [March 6, 2010, 7:50pm UTC](https://www.ruby-forum.com/t/form-for-submit-and-parameters-disappearing/184688/2 "2010-03-06T19:50:22Z")

</div>

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’ %\>

 \<%= f.submit shnI18n.literal('search\_for\_connection') %\> 
\<% 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?

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [March 6, 2010, 10:35pm UTC](https://www.ruby-forum.com/t/form-for-submit-and-parameters-disappearing/184688/3 "2010-03-06T22:35:59Z")

</div>

On 6 March 2010 18:50, Ralph S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [March 7, 2010, 2:37pm UTC](https://www.ruby-forum.com/t/form-for-submit-and-parameters-disappearing/184688/4 "2010-03-07T14:37:36Z")

</div>

On 7 March 2010 11:00, Ralph S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> form\_for cannot be, uh, “internationalized” because the various flavors  
> ‘connected\_to\_country’),
> 
> 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  
> [ActionView::Helpers::FormHelper](http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html).

What is wrong with  
\<%= hidden\_field\_tag “locale”, params[:locale] %\>

Colin

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [March 7, 2010, 3:14pm UTC](https://www.ruby-forum.com/t/form-for-submit-and-parameters-disappearing/184688/5 "2010-03-07T15:14:48Z")

</div>

Colin L. wrote:

> On 7 March 2010 11:00, Ralph S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > form\_for cannot be, uh, “internationalized” because the various flavors  
> > ‘connected\_to\_country’),  
> > ï¿½
> > 
> > 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  
> > [ActionView::Helpers::FormHelper](http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html).
> 
> What is wrong with  
> \<%= hidden\_field\_tag “locale”, params[:locale] %\>
> 
> Colin

I 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.

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [March 7, 2010, 12:00pm UTC](https://www.ruby-forum.com/t/form-for-submit-and-parameters-disappearing/184688/6 "2010-03-07T12:00:44Z")

</div>

Colin L. 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 [Internationalization (I18n) — Ruby on Rails Guides](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| %\>  
  
  
\<%= f.select :country,  
language\_neutral\_array\_of\_countries,  
:prompt =\> shnI18n.literal(‘enter\_country’) %\>

 \<%= f.submit shnI18n.literal('search\_for\_connection') %\> 
\<% end %\> - - - - - - -

You will note the

The first is the critical one where the locale is being passed.  
The second 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  
[ActionView::Helpers::FormHelper](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”

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [March 9, 2010, 6:42pm UTC](https://www.ruby-forum.com/t/form-for-submit-and-parameters-disappearing/184688/7 "2010-03-09T18:42:56Z")

</div>

Ralph S. wrote:

> Colin L. 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 [Internationalization (I18n) — Ruby on Rails Guides](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| %\>  
>   
>   
> […]

Why not store the locale in the session, instead of passing around  
hidden fields?

## Best,

Marnen Laibow-Koser

> **[marnen.org: Homepage of Marnen Laibow-Koser](https://marnen.org/)**

[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [March 14, 2010, 12:55am UTC](https://www.ruby-forum.com/t/form-for-submit-and-parameters-disappearing/184688/8 "2010-03-14T00:55:11Z")

</div>

Marnen Laibow-Koser wrote:

> Why not store the locale in the session, instead of passing around  
> hidden fields?

From [Internationalization (I18n) — Ruby on Rails Guides](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.

* * *
