Class: SystemSettings::SettingsController

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

Constant Summary collapse

RETURN_ATTRIBUTES =
["id", "name", "type", "value", "description"].freeze

Instance Method Summary collapse

Instance Method Details

#indexObject



7
8
9
10
# File 'app/controllers/system_settings/settings_controller.rb', line 7

def index
  @settings = SystemSettings::Setting.order(:name)
  render json: @settings.map { |s| s.as_json(only: RETURN_ATTRIBUTES) }
end

#showObject



12
13
14
15
16
# File 'app/controllers/system_settings/settings_controller.rb', line 12

def show
  @setting = SystemSettings::Setting.find(params[:id])
  add_authenticity_token
  render json: @setting.as_json(only: RETURN_ATTRIBUTES)
end

#updateObject



18
19
20
21
22
23
24
25
# File 'app/controllers/system_settings/settings_controller.rb', line 18

def update
  @setting = SystemSettings::Setting.find(params[:id])
  if @setting.update(value: params[:value])
    render json: @setting.as_json(only: RETURN_ATTRIBUTES)
  else
    render json: {errors: @setting.errors.as_json}, status: :unprocessable_entity
  end
end