Class: Sail::SettingsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Sail::SettingsController
- Defined in:
- app/controllers/sail/settings_controller.rb
Overview
SettingsController This is the main controller for settings Implements all actions for the dashboard and for the JSON API
Instance Method Summary collapse
-
#index ⇒ Object
rubocop:disable Metrics/AbcSize.
- #reset ⇒ Object
- #show ⇒ Object
- #switcher ⇒ Object
-
#update ⇒ Object
rubocop:enable Metrics/AbcSize.
Instance Method Details
#index ⇒ Object
rubocop:disable Metrics/AbcSize
15 16 17 18 19 20 |
# File 'app/controllers/sail/settings_controller.rb', line 15 def index @settings = Setting.by_query(s_params[:query]).ordered_by(s_params[:order_field]) @number_of_pages = (@settings.count.to_f / settings_per_page).ceil @settings = @settings.paginated(s_params[:page], settings_per_page) fresh_when(@settings) end |
#reset ⇒ Object
59 60 61 62 63 64 |
# File 'app/controllers/sail/settings_controller.rb', line 59 def reset respond_to do |format| @setting, @successful_update = Setting.reset(s_params[:name]) format.js { render :update } end end |
#show ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'app/controllers/sail/settings_controller.rb', line 31 def show respond_to do |format| format.json do render json: { value: Sail::Setting.get(s_params[:name]) } end end end |
#switcher ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/sail/settings_controller.rb', line 41 def switcher respond_to do |format| format.json do begin render json: { value: Sail::Setting.switcher(positive: s_params[:positive], negative: s_params[:negative], throttled_by: s_params[:throttled_by]) } rescue Sail::Setting::UnexpectedCastType head(:bad_request) rescue ActiveRecord::RecordNotFound head(:not_found) end end end end |
#update ⇒ Object
rubocop:enable Metrics/AbcSize
23 24 25 26 27 28 29 |
# File 'app/controllers/sail/settings_controller.rb', line 23 def update respond_to do |format| @setting, @successful_update = Setting.set(s_params[:name], s_params[:value]) format.js {} format.json { @successful_update ? head(:ok) : head(:conflict) } end end |