Reputation: 4922
Let's say I have this line in my controller
redirect_to "/sessions/try", provider: 5
and this is my try.html.erb
<h1>try</h1>
<%= provider %>
Obviously this doesn't work, but how would I get 'provider' to show up in my html file?
Upvotes: 1
Views: 481
Reputation: 7405
If you do not have a named route for /sessions/try
, then you'll have to hardcode the params into the string that you pass to redirect_to
:
redirect_to "/sessions/try?provider=5"
or
hash = { provider: 5 }
redirect_to "/sessions/try?#{hash.to_param}"
But if you have named route like try_sessions_path
, then you can use:
redirect_to try_sessions_path(provider: 5)
In your view, you will then get the keys in params
hash:
<%= params[:provider] %>
Upvotes: 1
Reputation: 21961
Send provider as params
redirect_to "/sessions/try?provider=5"
Than at, try.html.erb
<h1>try</h1>
<%= params[:provider] %>
Upvotes: 2