Class: ConfigManager::TogglesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/config_manager/toggles_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

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

#destroyObject

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

#dumpObject

POST /toggles/dump



49
50
51
# File 'app/controllers/config_manager/toggles_controller.rb', line 49

def dump
		send_data Toggle.to_yaml, :filename => 'toggles.yml'
end

#indexObject

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

#loadObject

POST /toggles/load



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/config_manager/toggles_controller.rb', line 34

def load
if params[:file]
	loads, failures = Toggle.from_yaml(params[:file].tempfile)
	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
else
	flash[:error] = "You must choose a file"
end
		rescue 
	flash[:error] = "Couldn't load toggles. Did you choose a valid file?"
ensure
	redirect_to toggles_url
end