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
11
# File 'app/controllers/system_settings/settings_controller.rb', line 7

def index
  @total_count = SystemSettings::Setting.count
  @settings = SystemSettings::Setting.order(:name).extending(SystemSettings::Pagination).page(params[:page], per_page: params[:per])
  render json: {items: @settings.map { |s| s.as_json(only: RETURN_ATTRIBUTES) }, total_count: @total_count}
end

#showObject



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

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

#updateObject



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

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