Reputation: 171
I'm new with rails. I have used the redirect_to
with params
in my action, but now I don't know how to show these params
to my view?
Upvotes: 6
Views: 29854
Reputation: 10885
Try this variants:
redirect_to controller: 'thing', action: 'edit', id: 3, something: 'else'
redirect_to thing_path(@thing, foo: params[:foo])
Also, this link should be helpful for you.
Upvotes: 11
Reputation: 2575
Actually if you have sent something with redirect - you have passed it like GET params. In this case you can access them from your params
hash.
If you redirect like:
redirect_to :controller => 'users', :action => 'edit', :id => 1, :param_a => 1, :param_b => 2
You have url like:
http://localhost:3000/users/1/edit?param_a=1¶m_b=2
So you can access :param_a
and :param_b
in your view from params hash:
<%= params[:param_a] %>
<%= params[:param_b] %>
Upvotes: 5