Link_to :post => true, w/ hidden extra params

Does anyone know if it’s possible to generate a link_to with :post =>
true and have extra params that do not appear in the url but still get
passed to the controller. i.e.

link_to { :controller => ‘things’, :action => ‘update’, :id => @thing,
:translucency => 42 }, :post => true

generates a post to the url

/things/update/1?translucency=42

Looking at the source, I can see where rails is generating the imaginary
form (f) with javascript

var f = document.createElement(‘form’); this.parentNode.appendChild(f);
f.method = ‘POST’; f.action = this.href; f.submit();

It doesn’t seem far fetched (to me) for Rails to be able to keep going
and add an element to that form with something like…

h = document.createElement(‘input’); h.type = ‘hidden’; h.name =
‘translucency’, h.value = 42; f.appendChild(h)

so that the url would simply become…

/things/update/1

I know that I could just create the form myself, but that’s not as fun
as having Rails do all the work for me. :wink:

Jon G. wrote:

Does anyone know if it’s possible to generate a link_to with :post =>
true and have extra params that do not appear in the url but still get
passed to the controller. i.e.

link_to { :controller => ‘things’, :action => ‘update’, :id => @thing,
:translucency => 42 }, :post => true

Actually, that was supposed to be…

link_to { :controller => ‘things’, :action => ‘update’, :id => @thing,
‘thing[translucency]’ => 42 }, :post => true

Jon G. wrote:

Does anyone know if it’s possible to generate a link_to with :post =>
true and have extra params that do not appear in the url but still get
passed to the controller. i.e.

You could write a custom helper to generate the javascript you need, or
even better just use a redirect after your state changing action. You
might be interested in the PRG pattern:

zsombor

Company - http://primalgrasp.com
Thoughts - http://deezsombor.blogspot.com