2017-01-12 14:46:24 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-10 15:27:03 -04:00
|
|
|
module Admin
|
|
|
|
class SettingsController < BaseController
|
|
|
|
def index
|
|
|
|
@settings = Setting.all_as_records
|
|
|
|
end
|
2017-01-12 14:46:24 -05:00
|
|
|
|
2017-04-10 15:27:03 -04:00
|
|
|
def update
|
|
|
|
@setting = Setting.where(var: params[:id]).first_or_initialize(var: params[:id])
|
|
|
|
value = settings_params[:value]
|
2017-01-12 14:46:24 -05:00
|
|
|
|
2017-04-10 15:27:03 -04:00
|
|
|
# Special cases
|
|
|
|
value = value == 'true' if @setting.var == 'open_registrations'
|
2017-01-12 14:46:24 -05:00
|
|
|
|
2017-04-10 15:27:03 -04:00
|
|
|
if @setting.value != value
|
|
|
|
@setting.value = value
|
|
|
|
@setting.save
|
|
|
|
end
|
2017-04-04 09:26:57 -04:00
|
|
|
|
2017-04-10 15:27:03 -04:00
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to admin_settings_path }
|
|
|
|
format.json { respond_with_bip(@setting) }
|
|
|
|
end
|
2017-01-12 14:46:24 -05:00
|
|
|
end
|
|
|
|
|
2017-04-10 15:27:03 -04:00
|
|
|
private
|
2017-04-04 09:26:57 -04:00
|
|
|
|
2017-04-10 15:27:03 -04:00
|
|
|
def settings_params
|
|
|
|
params.require(:setting).permit(:value)
|
|
|
|
end
|
2017-04-04 09:26:57 -04:00
|
|
|
end
|
2017-01-12 14:46:24 -05:00
|
|
|
end
|