I have a HTML-form, that when submitted calles
the action called 'abc'. But abc needs to redirect_to
a different action, passing to it the 'params' variable.
Any suggestions how to use redirect_to passing it
the params variable ?
I'm not sure which of 2 problems you're having, but both have short answers so ...
To pass parameters with redirect_to you simply add them. Like ...
redirect_to :controller => 'another', :action => 'def', :param1 => 'some', :param2 => 'thing', :param => 'else'
I'm guessing you're asking about the fact that parameters only 'live' for one request-response cycle. redirect_to ends one cycle and starts another so, in the situation you've outlined, you'll need to save them to (a) local variable(s) in the first method, then add them to the redirect_to to receive them in the second. Of course, you could also store them in the session or in the database too.
this would work, however, there is the problem of nested params, such
as what is submitted from a form using form tag helpers where rails
handles naming the form fields and thus you could end up with a params
hash such as
{ "user" => { "name" => "bob" } }
this would not work as it would end up with a query string like
?user=namebob in the redirect url instead of ?user[name]=bob
What happens when you don't know what
varaibles 'params' contains, so you want to
pass all of them with the redirect ?
I don't understand this question. The params hash will contain keys for every element in the form you submitted. Some may have an empty string for their value, but they'll all be there. If you only want to pass along the ones that have values, then you'll have to examine them before passing them along.
BTW... according to Pickaxe, join is not a defined method on a Hash.
Yeah. That’s a HTTP method issue there. You might not want to pass wall the params there ‘cause it seems to be breaking your routes’ styling. Or just bite the bullet on that ugly URL. I’d opt for the former but that’s me.