Module: ActiveadminSettingsCached::DSL

Defined in:
lib/activeadmin_settings_cached/dsl.rb

Instance Method Summary collapse

Instance Method Details

#active_admin_settings_page(options = {}, &block) ⇒ Object

Declares settings function

Options:

model_name

settings model name override (default: uses name from global config.)

starting_with

each key must starting with, (default: nil)

template

custom template rendering (default: ‘admin/settings/index’)

template_object

object to use in templates (default: ActiveadminSettingsCached::Model instance)

display

display settings override (default: nil)

title

title value override (default: I18n.t(‘settings.menu.label’))



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/activeadmin_settings_cached/dsl.rb', line 13

def active_admin_settings_page(options = {}, &block)
  options.assert_valid_keys(*Options::VALID_OPTIONS)

  options = Options.options_for(options)
  coercion = Coercions.new(options[:template_object].defaults, options[:template_object].display)

  content title: options[:title] do
    render partial: options[:template], locals: { settings_model: options[:template_object] }
  end

  page_action :update, method: :post do
    settings_params = params.require(:settings).permit(options[:template_object].defaults.keys)

    coercion.cast_params(settings_params) do |name, value|
      options[:template_object][name] = value
    end

    flash[:success] = t('activeadmin_settings_cached.settings.update.success'.freeze)
    redirect_to :back
  end

  instance_eval(&block) if block_given?
end