Class: InstanceConfigurationController

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

Instance Method Summary collapse

Instance Method Details

#indexObject



26
27
28
29
30
31
32
# File 'app/controllers/instance_configuration_controller.rb', line 26

def index
  authorize! :show, Iqvoc.config

  @settings = Iqvoc.config.defaults.each_with_object({}) { |(key, default_value), hsh|
    hsh[key] = serialize(Iqvoc.config[key], default_value)
  }
end

#updateObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/instance_configuration_controller.rb', line 34

def update
  authorize! :update, Iqvoc.config

  # deserialize and save configuration settings
  errors = []
  params[:config].each { |key, value|
    unless Iqvoc.config.defaults.include?(key)
      errors << t("txt.controllers.instance_configuration.invalid_key", :key => key)
    else
      default_value = Iqvoc.config.defaults[key]
      begin
        Iqvoc.config[key] = deserialize(value, default_value)
      rescue TypeError => exc
        errors << t("txt.controllers.instance_configuration.invalid_value",
            :key => key, :error_message => exc.message)
      end
    end
  }

  if errors.none?
    flash[:success] = t("txt.controllers.instance_configuration.update_success")
  else
    flash[:error] = t("txt.controllers.instance_configuration.update_error",
        :error_messages => errors.join("; "))
  end

  redirect_to instance_configuration_url
end