demarches-normaliennes/app/controllers/concerns/query_params_store_concern.rb
sebastiencarceles 6c5b82ebbf filter out locale from stored query params
As 'locale' isn't a param we want to prefill a dossier, we ignore it
and remove it from the stored query params.
2023-02-09 13:51:52 +01:00

31 lines
747 B
Ruby

module QueryParamsStoreConcern
extend ActiveSupport::Concern
included do
helper_method :stored_query_params?
end
def store_query_params
# Don't override already stored params, because we could do goings and comings with authentication, and
# lost previously stored params
return if stored_query_params? || filtered_query_params.empty?
session[:stored_params] = filtered_query_params.to_json
end
def retrieve_and_delete_stored_query_params
return {} unless stored_query_params?
JSON.parse(session.delete(:stored_params))
end
def stored_query_params?
session[:stored_params].present?
end
private
def filtered_query_params
request.query_parameters.except(:locale, "locale")
end
end