Reputation: 969
I am using devise. I want to redirect to previous page after sign in process is successful. The problem I am having is that the request.referer always has sign_in URL in it. How can I get the URL of the previous page without some explicit hooks.
def after_sign_in_path_for(resource)
stored_location_for(resource) || request.referer || search_index_path
end
Upvotes: 2
Views: 1912
Reputation: 354
inside action controller put
before_action :store_return_to, unless: :devise_controller?
def store_return_to
store_location_for(resource, request.url)
end
Where resource
is your devise model, :user
per example
Upvotes: 0
Reputation: 4534
I am not on my dev machine so can't verify it. But it should be.
#application controller
def store_return_to
session[:return_to] = request.uri
end
def redirect_back_or_default
redirect_to(session[:return_to] || root_url)
session[:return_to] = nil
end
#home_controller | or any other controller we want to use it.
before_filter :store_return_to
# Session/login_controlelr
Call this function after successful sign_in or sign_up
redirect_back_or_default
A bit off the track(devise) but will be helpful.
Upvotes: 3