Class: BMC::FiltersController

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(json) ⇒ Object



7
8
9
10
11
# File 'app/controllers/bmc/filters_controller.rb', line 7

def self.parse(json)
  JSON.parse(json.to_s).with_indifferent_access
rescue JSON::ParserError
  {}.with_indifferent_access
end

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/bmc/filters_controller.rb', line 13

def create
  filters = self.class.parse(cookies[:filters])
  filters.merge! params.fetch(:filters, {}).permit!.to_h

  cookies[:filters] = {
    :value   => JSON.dump(filters),
    :expires => 1.year.from_now,
    :path    => "/",
  }

  redirect_to back_url
end