| Module | RefreshTo::ControllerMethods |
| In: |
lib/refresh_to.rb
|
redirect_back_or_default() is a method provided by acts_as_authenticated (and other auth plugins?) that looks for a :return_to session variable, so that a user can be sent right back to the page they were at before they had to login.
refresh_back_or_default() is to redirect_back_or_default() as refresh_to() is to redirect_to().
Use refresh_back_or_default() in your controllers just like you would use the standard redirect_back_or_default() method.
refresh_back_or_default() accepts a URL as a string, a named route, or a hash. Examples:
* refresh_back_or_default('/users/profile')
* refresh_back_or_default(user_profile_url)
* refresh_back_or_default(:controller => "users", :action => "profile")
Just be careful in your functional tests - assert_response :redirect and assert_redirected_to my_url don‘t work with refresh_back_or_default().
# File lib/refresh_to.rb, line 56
56: def refresh_back_or_default(default)
57: session[:return_to] ? refresh_to(session[:return_to]) : refresh_to(default)
58: session[:return_to] = nil
59: end
Use refresh_to() in your controllers just like you would use the standard redirect_to() method.
refresh_to() accepts a URL as a string, a named route, or a hash.
Examples:
* refresh_to('/users/profile')
* refresh_to(user_profile_url)
* refresh_to(:controller => "users", :action => "profile")
Just be careful in your functional tests - assert_response :redirect and assert_redirected_to my_url don‘t work with refresh_to().
# File lib/refresh_to.rb, line 17
17: def refresh_to(path = {})
18: case path.class.to_s
19: when 'Hash'
20: @path = url_for(path)
21: when 'String'
22: @path = path
23: else
24: raise ArgumentError, "expected a URL hash or a string path, but got #{path}"
25: end
26: render(:inline => %q(
27: <html>
28: <head>
29: <meta http-equiv="refresh" content="0;url=<%= @path %>">
30: </head>
31: </html>)
32: )
33: end