Class: Cambium::Admin::SettingsController

Inherits:
Cambium::AdminController
  • Object
show all
Defined in:
app/controllers/cambium/admin/settings_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



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

def index
  expected_keys = admin_view.form.edit.fields.to_h.stringify_keys.keys
  current_keys = Cambium::Setting.keys
  # Add anything that's missing
  (expected_keys - current_keys).each do |key|
    Cambium::Setting.create(:key => key)
  end
  @collection = admin_model.alpha
  # Remove anything extra
  extra_keys = @collection.collect(&:key) - expected_keys
  if extra_keys.size > 0
    Cambium::Setting.where(:key => extra_keys).destroy_all
    @collection = admin_model.alpha
  end
  respond_to do |format|
    format.html
    format.csv { send_data admin.to_csv(@collection) }
  end
end