Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails redirect_to with params

I want to pass parameters (a hash) to redirect_to, how to do this? For example:

hash = { :parm1 => "hi", :parm2 => "hi" }

and I want to redirect to page /hello

URL like this: /hello?parm1=hi&parm2=hi

like image 636
ygnhzeus Avatar asked Mar 12 '12 04:03

ygnhzeus


People also ask

How do I redirect back in rails?

In Rails 4. x, for going back to previous page we use redirect_to :back. However sometimes we get ActionController::RedirectBackError exception when HTTP_REFERER is not present. This works well when HTTP_REFERER is present and it redirects to previous page.

Does redirect_to return?

redirect_to is not return Keep in mind that redirect_to does not cause the action to stop executing. It is not like calling return in a Ruby method.


1 Answers

If you don't have a named route for /hello then you'll have to hardcode the params into the string that you pass to redirect_to.

But if you had something like hello_path then you could use redirect_to hello_path(:param1 => 1, :param2 => 2)

like image 112
James Avatar answered Sep 21 '22 07:09

James