Class: Dorsale::SmallData::FiltersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/dorsale/small_data/filters_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_user_scope

Instance Method Details

#back_urlObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/dorsale/small_data/filters_controller.rb', line 26

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

#createObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/dorsale/small_data/filters_controller.rb', line 5

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