Skip to content

Instantly share code, notes, and snippets.

@westonganger
Last active March 30, 2023 05:06
Show Gist options
  • Save westonganger/ef51c005c8a033436a1b8f074bf37463 to your computer and use it in GitHub Desktop.
Save westonganger/ef51c005c8a033436a1b8f074bf37463 to your computer and use it in GitHub Desktop.
Get Previous Route in Rails 3/4+ App
ApplicationController < ActionController::Base
after_filter :set_route_info
def set_route_info
session[:return_to] = request.url
prev_route = Rails.application.routes.recognize_path(URI(session[:return_to]).path)
session[:previous_controller] = prev_route[:action]
session[:previous_action] = prev_route[:action]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment