demarches-normaliennes/app/controllers/concerns/query_params_store_concern.rb
Sébastien Carceles b8ff0ba4a2
feat(demarche): sign up when prefilling a dossier (#8247)
* store prefill params in session

Instead of using query params on /dossier/new, we assume the user comes
from /commencer/:path, which is the new prefill link.

There, we store the prefill params in session, and use them to prefill
the dossier when creating it, in /dossiers/new.

* spec: cover the case

* review: serialize with json instead of yaml

* review: rename method

* review: store only query params

* review: comment why we dont override already stored params
2022-12-15 10:58:17 +01:00

17 lines
538 B
Ruby

module QueryParamsStoreConcern
extend ActiveSupport::Concern
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 session[:stored_params].present? || request.query_parameters.empty?
session[:stored_params] = request.query_parameters.to_json
end
def retrieve_and_delete_stored_query_params
return {} if session[:stored_params].blank?
JSON.parse(session.delete(:stored_params))
end
end