Class: Sail::SettingsController

Inherits:
ApplicationController show all
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

Instance Method Details

#indexObject



9
10
11
12
13
14
# File 'app/controllers/sail/settings_controller.rb', line 9

def index
  @settings = Setting.by_query(s_params[:query])
  @number_of_pages = (@settings.count.to_f / Sail::Setting::SETTINGS_PER_PAGE).ceil
  @settings = @settings.paginated(s_params[:page])
  fresh_when(@settings)
end

#resetObject



52
53
54
55
56
57
# File 'app/controllers/sail/settings_controller.rb', line 52

def reset
  respond_to do |format|
    @setting, @successful_update = Setting.reset(s_params[:name])
    format.js { render :update }
  end
end

#showObject



24
25
26
27
28
29
30
31
32
# File 'app/controllers/sail/settings_controller.rb', line 24

def show
  respond_to do |format|
    format.json do
      render json: {
        value: Sail::Setting.get(s_params[:name])
      }
    end
  end
end

#switcherObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/sail/settings_controller.rb', line 34

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

#updateObject



16
17
18
19
20
21
22
# File 'app/controllers/sail/settings_controller.rb', line 16

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