Module: ConfigurableEngine::ConfigurablesControllerMethods

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

Instance Method Summary collapse

Instance Method Details

#showObject



5
6
7
8
# File 'lib/configurable_engine/configurables_controller_methods.rb', line 5

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

#updateObject



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

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