Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save salkar/ff87c13c6b2175cdc10f to your computer and use it in GitHub Desktop.
Save salkar/ff87c13c6b2175cdc10f to your computer and use it in GitHub Desktop.
Ruby on Rails: Return back if it is possible
To after_sign_in_path_for(resource) in ApplicationController
if request.env['HTTP_REFERER']
begin
route_params = Rails.application.routes.recognize_path(URI(request.referrer).path, {method: :get})
if route_params[:controller].include?('devise')
root_path
else
request.env['HTTP_REFERER']
end
rescue
root_url
end
else
root_url
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment