Class: ConfigManager::SettingsController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /settings



13
14
15
16
17
18
19
20
21
# File 'app/controllers/config_manager/settings_controller.rb', line 13

def create
	@setting = Setting.create(params[:setting])
	if @setting.valid?
		flash[:notice] = "Setting successfully created/updated"
	else
		flash[:error] = "Failed to create/update setting: #{@setting.message}"
	end
	redirect_to settings_url
end

#destroyObject

DELETE /settings/:id



24
25
26
27
28
29
# File 'app/controllers/config_manager/settings_controller.rb', line 24

def destroy
	Setting.delete(params[:id])
	flash[:notice] = "#{params[:id]} has been deleted!"

	redirect_to settings_url
end

#dumpObject

GET /settings/dump



32
33
34
# File 'app/controllers/config_manager/settings_controller.rb', line 32

def dump
	send_data Setting.to_yaml, :filename => 'setting.yml'
end

#indexObject

GET /settings



4
5
6
7
8
9
10
# File 'app/controllers/config_manager/settings_controller.rb', line 4

def index
	@settings = Setting.all.sort {|a,b| a.id <=> b.id}
	@setting = params[:setting_id] ? 
			Setting.find(params[:setting_id], true) :
			Setting.new(nil, nil, nil)
	@tags = Setting.tags.join(', ')
end

#loadObject

POST /settings/load



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

def load
	if params[:file]
		loads, failures = Setting.from_yaml(params[:file].tempfile)
		flash[:notice] = "#{loads} settings have been loaded from the yaml file." if loads > 0
		flash[:error] = "#{failures} settings 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 settings. Did you choose a valid file?"
ensure
	redirect_to settings_url
end