Module: ConfigurableEngine::ConfigurablesControllerMethods

Included in:
ConfigurablesController
Defined in:
lib/configurable_engine/configurables_controller_methods.rb

Instance Method Summary collapse

Instance Method Details

#showObject



3
4
5
6
# File 'lib/configurable_engine/configurables_controller_methods.rb', line 3

def show
  @keys = Configurable.keys
  render 'configurable_engine/configurables/show'
end

#updateObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/configurable_engine/configurables_controller_methods.rb', line 8

def update
  failures = Configurable
    .keys.map do |key|
      Configurable.find_by_name(key) ||
        Configurable.create {|c| c.name = key}
    end.reject do |configurable|
      configurable.value = params[configurable.name]
      configurable.save
    end

  if failures.empty?
    redirect_to(action: :show, :notice => "Changes successfully updated")
  else
    flash[:error] = failures.flat_map(&:errors).flat_map(&:full_messages).join(',')
    redirect_to(action: :show)
  end
end