Module: Decidim::FilterParamsHelper
- Included in:
- ViewModel
- Defined in:
- app/helpers/decidim/filter_params_helper.rb
Overview
A helper to allow only Decidim params to be added to a link. This is useful when we want to preserve the params from a search, ordering or paginating results. Using this, we can link back to where the user was at the show page.
Instance Method Summary collapse
-
#filter_link_params(params = nil) ⇒ Object
Public: Builds a hash to be added to a _path or _url method with only allowed params.
Instance Method Details
#filter_link_params(params = nil) ⇒ Object
Public: Builds a hash to be added to a _path or _url method with only allowed params.
params - An optional Hash with the values of the params. It will try to get them from the controller if none are present.
Returns a Hash.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/helpers/decidim/filter_params_helper.rb', line 16 def filter_link_params(params = nil) return {} if params.blank? && (!respond_to?(:controller) || !controller.respond_to?(:params)) params = controller.params.to_unsafe_h if params.blank? params.stringify_keys.slice( "order", "filter", "page", "per_page", "locale" ) end |