1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-23 15:19:38 +02:00
Maybe/app/controllers/concerns/store_location.rb
Zach Gollwitzer 0af5faaa9f
Make encryption config optional for self hosting users (#1476)
* Fix redirect 404 bug

* Make encryption optional for self-hosters

* Fix test
2024-11-18 10:47:05 -05:00

41 lines
793 B
Ruby

module StoreLocation
extend ActiveSupport::Concern
included do
helper_method :previous_path
before_action :store_return_to
after_action :clear_previous_path
rescue_from ActiveRecord::RecordNotFound, with: :handle_not_found
end
def previous_path
session[:return_to] || fallback_path
end
private
def handle_not_found
if request.fullpath == session[:return_to]
session.delete(:return_to)
redirect_to fallback_path
else
head :not_found
end
end
def store_return_to
if params[:return_to].present?
session[:return_to] = params[:return_to]
end
end
def clear_previous_path
if request.fullpath == session[:return_to]
session.delete(:return_to)
end
end
def fallback_path
root_path
end
end