Class: ConfigManager::TogglesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ConfigManager::TogglesController
- Defined in:
- app/controllers/config_manager/toggles_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /toggles.
-
#destroy ⇒ Object
DELETE /toggles/:id.
-
#dump ⇒ Object
POST /toggles/dump.
-
#index ⇒ Object
GET /toggles.
-
#load_default ⇒ Object
POST /toggles/load_default.
Instance Method Details
#create ⇒ Object
POST /toggles
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/controllers/config_manager/toggles_controller.rb', line 10 def create @toggle = Toggle.create(params[:toggle]) if @toggle.valid? flash[:notice] = "Toggle successfully created/updated" else flash[:error] = "Failed to create/update toggle: #{@toggle.message}" end redirect_to toggles_url rescue Rails.logger.error "Error raised trying to create/update toggle. #{$!}. #{$!.backtrace.take(3)}" flash[:error] = "Error raised trying to create/update toggle: #{$!}" redirect_to toggles_url end |
#destroy ⇒ Object
DELETE /toggles/:id
26 27 28 29 30 31 |
# File 'app/controllers/config_manager/toggles_controller.rb', line 26 def destroy Toggle.delete(params[:id]) flash[:notice] = "#{params[:id]} has been deleted!" redirect_to toggles_url end |
#dump ⇒ Object
POST /toggles/dump
47 48 49 50 51 52 53 54 55 |
# File 'app/controllers/config_manager/toggles_controller.rb', line 47 def dump path = Rails.root.join('config/config_manager_toggles.yml') Toggle.to_yaml(path) flash[:notice] = "Toggles dumped to #{path}" rescue flash[:error] = "Failed to dump toggles to #{path}" ensure redirect_to toggles_url end |
#index ⇒ Object
GET /toggles
4 5 6 7 |
# File 'app/controllers/config_manager/toggles_controller.rb', line 4 def index @toggles = Toggle.toggles @toggle = Toggles::Definition.new(params[:toggle_name]) end |
#load_default ⇒ Object
POST /toggles/load_default
34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/config_manager/toggles_controller.rb', line 34 def load_default loads, failures = Toggle.from_yaml(Rails.root.join('config/config_manager_toggles.yml')) flash[:notice] = "#{loads} toggles have been loaded from the yaml file." if loads > 0 flash[:error] = "#{failures} toggles failed to be loaded from the yaml file" if failures > 0 redirect_to toggles_url rescue Errno::ENOENT flash[:error] = "Couldn't load toggles. config_manager_toggles.yml not found in config directory." redirect_to toggles_url end |