2017-01-13 06:46:24 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Admin::SettingsController < ApplicationController
|
|
|
|
before_action :require_admin!
|
|
|
|
|
|
|
|
layout 'admin'
|
|
|
|
|
|
|
|
def index
|
|
|
|
@settings = Setting.all_as_records
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@setting = Setting.where(var: params[:id]).first_or_initialize(var: params[:id])
|
2017-04-04 23:26:57 +10:00
|
|
|
value = settings_params[:value]
|
2017-01-13 06:46:24 +11:00
|
|
|
|
2017-04-04 23:26:57 +10:00
|
|
|
# Special cases
|
|
|
|
value = value == 'true' if @setting.var == 'open_registrations'
|
|
|
|
|
|
|
|
if @setting.value != value
|
|
|
|
@setting.value = value
|
2017-01-13 06:46:24 +11:00
|
|
|
@setting.save
|
|
|
|
end
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to admin_settings_path }
|
|
|
|
format.json { respond_with_bip(@setting) }
|
|
|
|
end
|
|
|
|
end
|
2017-04-04 23:26:57 +10:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def settings_params
|
|
|
|
params.require(:setting).permit(:value)
|
|
|
|
end
|
2017-01-13 06:46:24 +11:00
|
|
|
end
|