Sha256: a70c836c8f9b7cfdd226ddf3da39b94881e081d8e3ef209d262aaa1fa1dca67a

Contents?: true

Size: 1.1 KB

Versions: 33

Compression:

Stored size: 1.1 KB

Contents

module Dorsale
  module SmallData
    class FiltersController < ::Dorsale::ApplicationController

      def create
        new_filters = params[:filters] || {}

        new_filters.each do |key, value|
          new_filters[key] = "" if value == "0"
        end

        filters = Filter.new(cookies)
        new_filters = filters.read.merge(new_filters)
        filters.store(new_filters)

        # Rewrite cookie with 1 year expiry
        cookies[:filters] = {
          :value    => cookies[:filters],
          :expires => 1.year.from_now,
          :path     => "/",
        }

        redirect_to back_url
      end

      def back_url
        urls = [
          params[:back_url],
          request.referer,
          (main_app.root_path rescue nil)
        ]

        url = urls.select(&:present?).first

        # Delete page page
        base, query_string = url.split("?")
        query_string = query_string.to_s.split("&").delete_if { |p| p.include?("page=") }.join("&")
        query_string = "?#{query_string}" if query_string.present?
        url = base + query_string

        url
      end

    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
dorsale-2.7.3 app/controllers/dorsale/small_data/filters_controller.rb
dorsale-2.7.2 app/controllers/dorsale/small_data/filters_controller.rb
dorsale-2.7.1 app/controllers/dorsale/small_data/filters_controller.rb
dorsale-2.7.0 app/controllers/dorsale/small_data/filters_controller.rb
dorsale-2.6.8 app/controllers/dorsale/small_data/filters_controller.rb
dorsale-2.6.7 app/controllers/dorsale/small_data/filters_controller.rb
dorsale-2.6.6 app/controllers/dorsale/small_data/filters_controller.rb
dorsale-2.6.5 app/controllers/dorsale/small_data/filters_controller.rb
dorsale-2.6.4 app/controllers/dorsale/small_data/filters_controller.rb
dorsale-2.6.3 app/controllers/dorsale/small_data/filters_controller.rb
dorsale-2.6.2 app/controllers/dorsale/small_data/filters_controller.rb
dorsale-2.6.1 app/controllers/dorsale/small_data/filters_controller.rb
dorsale-2.6.0 app/controllers/dorsale/small_data/filters_controller.rb
dorsale-2.5.0 app/controllers/dorsale/small_data/filters_controller.rb
dorsale-2.4.3 app/controllers/dorsale/small_data/filters_controller.rb
dorsale-2.4.2 app/controllers/dorsale/small_data/filters_controller.rb
dorsale-2.4.1 app/controllers/dorsale/small_data/filters_controller.rb
dorsale-2.4.0 app/controllers/dorsale/small_data/filters_controller.rb
dorsale-2.3.5 app/controllers/dorsale/small_data/filters_controller.rb
dorsale-2.3.4 app/controllers/dorsale/small_data/filters_controller.rb