Redirect_to with parameters. How to convey them in my opinion?

I am new to rails. I used redirect_to with params in my action, but now I don’t know how to show these params in my view?

+6
source share
2 answers

Try the following options:

  • redirect_to controller: 'thing', action: 'edit', id: 3, something: 'else'
  • redirect_to thing_path(@thing, foo: params[:foo])

In addition, this link should be useful to you .

+11
source

In fact, if you sent something with a redirect, you passed it as a GET parameter. In this case, you can access them from the params hash.

If you redirect, for example:

 redirect_to :controller => 'users', :action => 'edit', :id => 1, :param_a => 1, :param_b => 2 

You have a url:

 http://localhost:3000/users/1/edit?param_a=1&param_b=2 

Thus, you can access :param_a and :param_b in your view from the parameter hash:

 <%= params[:param_a] %> <%= params[:param_b] %> 
+4
source

Source: https://habr.com/ru/post/916476/


All Articles