module ActionInterceptor::ActionController::Base
Public Class Methods
included(base)
click to toggle source
# File lib/action_interceptor/action_controller/base.rb, line 7 def self.included(base) base.helper_method :current_page?, :current_url, :stored_url end
Protected Instance Methods
current_page?(url)
click to toggle source
# File lib/action_interceptor/action_controller/base.rb, line 13 def current_page?(url) # Return true for blank (blank links redirect to the same page) return true if url.blank? uri = Addressable::URI.parse(url) uri.path == request.path && ( uri.relative? || uri.host == request.host_with_port || ( uri.host == request.host && uri.port == request.port ) ) end
current_url()
click to toggle source
# File lib/action_interceptor/action_controller/base.rb, line 26 def current_url "#{request.protocol}#{request.host_with_port}#{request.fullpath}" end
delete_stored_url(options = {})
click to toggle source
Deletes to the stored url
# File lib/action_interceptor/action_controller/base.rb, line 64 def delete_stored_url(options = {}) strats = ActionInterceptor::Strategies.find_all(self, options[:strategies]) key = options[:key] || ActionInterceptor.config.default_key strats.each do |strat| strat.unset(key) end nil end
redirect_back(options = {})
click to toggle source
Redirects to the stored url and deletes it from storage
# File lib/action_interceptor/action_controller/base.rb, line 76 def redirect_back(options = {}) interceptor_options = options.slice(:key, :strategies) redirect_options = options.except(:key, :strategies) url = stored_url(interceptor_options) delete_stored_url(interceptor_options) # Prevent self redirects url = (ActionInterceptor.config.default_url || main_app.root_url) if current_page?(url) redirect_to url, redirect_options end
store_fallback(options = {})
click to toggle source
Stores the given url or the referer if no stored url is present
# File lib/action_interceptor/action_controller/base.rb, line 58 def store_fallback(options = {}) store_url({url: request.referer}.merge(options)) \ if stored_url(options).blank? end
store_url(options = {})
click to toggle source
Stores the given url or the current url If the current request is not a GET request, stores the referer instead
# File lib/action_interceptor/action_controller/base.rb, line 32 def store_url(options = {}) strats = ActionInterceptor::Strategies.find_all(self, options[:strategies]) key = options[:key] || ActionInterceptor.config.default_key url = options.has_key?(:url) ? options[:url] : (request.get? ? current_url : request.referer) strats.each{ |strat| strat.set(key, url) } url end
stored_url(options = {})
click to toggle source
Retrieves the stored url
# File lib/action_interceptor/action_controller/base.rb, line 45 def stored_url(options = {}) strats = ActionInterceptor::Strategies.find_all(self, options[:strategies]) key = options[:key] || ActionInterceptor.config.default_key strats.each do |strat| url = strat.get(key) return url unless url.blank? end nil end