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?
Send provider as params
redirect_to "/sessions/try?provider=5"
Than at, try.html.erb
<h1>try</h1>
<%= params[:provider] %>
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] %>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.