Permalink
Browse files

admin interface for editing settings

  • Loading branch information...
1 parent ed1e7bd commit c4d10fbc35ad67cc9f970aebb8a10d5a6b79fc3f @timriley committed Jun 30, 2008
@@ -1,9 +1,23 @@
class Admin::SettingsController < Admin::AdminController
- def edit
+ def show
@settings = Settings.instance
end
def update
@settings = Settings.instance
+
+ params[:settings].each_pair do |key, val|
+ # FIXME this is a security hole. Need to patch it.
+ @settings.send("#{key}=".to_sym, val)
+ end
+
+ respond_to do |format|
+ if @settings.save
+ flash[:notice] = 'Settings saved'
+ format.html { redirect_to admin_settings_path }
+ else
+ format.html { render 'index' }
+ end
+ end
end
end
View
@@ -1,6 +1,8 @@
class Settings
include Singleton
+ attr_accessor :password
+
# this allows us to read and write settings of any name
def method_missing(method_id, *arguments)
case method_id.to_s
@@ -18,14 +20,17 @@ def method_missing(method_id, *arguments)
end
def save
+ # encrypt the password
+ self.crypted_password = self.password unless self.password.blank?
+
File.open("#{Rails.root}/config/config.yml", 'w') { |f| YAML.dump(@raw_tree, f) }
end
+ protected
+
def tree
@raw_tree ||= YAML.load_file("#{Rails.root}/config/config.yml")
end
-
- private
def read_setting(key)
tree[Rails.env][key]
@@ -1 +0,0 @@
-hey there
@@ -0,0 +1,21 @@
+- if flash[:notice]
+ %p= flash[:notice]
+
+- form_for :settings, @settings, :url => admin_settings_path, :html => {:method => :put} do |f|
+ %p
+ = f.label :flickr_user_id, 'Flickr user ID'
+ %br
+ = f.text_field :flickr_user_id
+ %p
+ = f.label :synchronise_tag, 'Flickr photo tag'
+ %br
+ = f.text_field :synchronise_tag
+ %p
+ = f.label :password, 'Admin password'
+ %br
+ = f.text_field :password
+
+ %p
+ = f.submit 'Save'
+ or
+ = link_to 'Cancel', admin_settings_path
View
@@ -6,6 +6,6 @@
admin.resource :settings
admin.resource :login
admin.logout '/logout', :controller => 'logins', :action => 'destroy'
- admin.root :controller => 'settings', :action => 'edit'
+ admin.root :controller => 'settings', :action => 'show'
end
end

0 comments on commit c4d10fb

Please sign in to comment.