module PersistentParams
Public Class Methods
included(controller)
click to toggle source
# File lib/persistent_params.rb, line 10 def self.included(controller) controller.before_filter :check_last_params controller.extend ClassMethods end
Private Instance Methods
actions_to_persist_params()
click to toggle source
# File lib/persistent_params.rb, line 28 def actions_to_persist_params Array(persistent_params_config.only || 'index').map(&:to_s) end
check_last_params()
click to toggle source
# File lib/persistent_params.rb, line 17 def check_last_params return if skip_this_action? return clear_last_params if clear_last_params? return redirect_to_last_params if current_params.empty? self.last_params = current_params end
clear_last_params()
click to toggle source
# File lib/persistent_params.rb, line 36 def clear_last_params self.last_params = nil end
clear_last_params?()
click to toggle source
# File lib/persistent_params.rb, line 32 def clear_last_params? params[:clear].present? end
current_params()
click to toggle source
# File lib/persistent_params.rb, line 45 def current_params send(params_method).except(*ignored_keys) end
ignored_keys()
click to toggle source
# File lib/persistent_params.rb, line 53 def ignored_keys %w(controller action) end
last_params()
click to toggle source
# File lib/persistent_params.rb, line 61 def last_params session[last_params_key] || {} end
last_params=(scopes)
click to toggle source
# File lib/persistent_params.rb, line 65 def last_params=(scopes) session[last_params_key] = scopes end
last_params_key()
click to toggle source
# File lib/persistent_params.rb, line 69 def last_params_key "#{params[:controller]}__#{params[:action]}" end
params_method()
click to toggle source
# File lib/persistent_params.rb, line 49 def params_method persistent_params_config.params_method || :params end
persistent_params_config()
click to toggle source
# File lib/persistent_params.rb, line 57 def persistent_params_config self.class.persistent_params_config end
redirect_to_last_params()
click to toggle source
# File lib/persistent_params.rb, line 40 def redirect_to_last_params return if last_params.empty? redirect_to **last_params.symbolize_keys end
skip_this_action?()
click to toggle source
# File lib/persistent_params.rb, line 24 def skip_this_action? !actions_to_persist_params.include?(params[:action]) end