Sha256: 63051be935da228700d98983b1e51ce9b36f77396e70c0ec2a8fffe924c2c1fc

Contents?: true

Size: 938 Bytes

Versions: 24

Compression:

Stored size: 938 Bytes

Contents

# frozen_string_literal: true

module Decidim
  # 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.
  module FilterParamsHelper
    # 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.
    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
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
decidim-core-0.26.0 app/helpers/decidim/filter_params_helper.rb
decidim-core-0.26.0.rc2 app/helpers/decidim/filter_params_helper.rb
decidim-core-0.26.0.rc1 app/helpers/decidim/filter_params_helper.rb
decidim-core-0.25.2 app/helpers/decidim/filter_params_helper.rb
decidim-core-0.25.1 app/helpers/decidim/filter_params_helper.rb
decidim-core-0.25.0 app/helpers/decidim/filter_params_helper.rb
decidim-core-0.25.0.rc4 app/helpers/decidim/filter_params_helper.rb
decidim-core-0.25.0.rc3 app/helpers/decidim/filter_params_helper.rb
decidim-core-0.25.0.rc2 app/helpers/decidim/filter_params_helper.rb
decidim-core-0.25.0.rc1 app/helpers/decidim/filter_params_helper.rb
decidim-core-0.24.3 app/helpers/decidim/filter_params_helper.rb
decidim-core-0.23.6 app/helpers/decidim/filter_params_helper.rb
decidim-core-0.24.2 app/helpers/decidim/filter_params_helper.rb
decidim-core-0.23.5 app/helpers/decidim/filter_params_helper.rb
decidim-core-0.24.1 app/helpers/decidim/filter_params_helper.rb
decidim-core-0.24.0 app/helpers/decidim/filter_params_helper.rb
decidim-core-0.24.0.rc2 app/helpers/decidim/filter_params_helper.rb
decidim-core-0.23.4 app/helpers/decidim/filter_params_helper.rb
decidim-core-0.24.0.rc1 app/helpers/decidim/filter_params_helper.rb
decidim-core-0.23.3 app/helpers/decidim/filter_params_helper.rb