@@ -3,7 +3,13 @@ class AdminController < ApplicationController | |||||
end | end | ||||
def update | def update | ||||
# respond to form data... | |||||
if !params[:settings].nil? | |||||
params[:settings].each do |key, value| | |||||
## assert in list of valid settings... | |||||
## only if changed (i.e. not equal to get) | |||||
AdminSetting.set(key, value) | |||||
end | |||||
end | |||||
render 'index' | render 'index' | ||||
end | end | ||||
end | end |
@@ -1,8 +1,8 @@ | |||||
module AdminHelper | module AdminHelper | ||||
SETTINGS = [ | SETTINGS = [ | ||||
{:key => :site_name, :label => 'Site name'}, | |||||
{:key => :corporation, :label => 'Corporation'}, | |||||
{:key => :description, :label => 'Home page description', :textarea => true}, | |||||
{:key => :copyright, :label => 'Copyright'}, | |||||
{:key => 'site_name', :label => 'Site name'}, | |||||
{:key => 'corporation', :label => 'Corporation'}, | |||||
{:key => 'description', :label => 'Home page description', :textarea => true}, | |||||
{:key => 'copyright', :label => 'Copyright'}, | |||||
] | ] | ||||
end | end |
@@ -7,10 +7,7 @@ class AdminSetting < ActiveRecord::Base | |||||
end | end | ||||
def self.set(key, value) | def self.set(key, value) | ||||
setting = self.find_by(key: key) | |||||
setting.update(value: value) | |||||
Rails.cache.write("admin_setting/#{key}") do | |||||
value | |||||
end | |||||
self.find_by(key: key).update(value: value) | |||||
Rails.cache.write("admin_setting/#{key}", value) | |||||
end | end | ||||
end | end |
@@ -8,11 +8,11 @@ | |||||
<table> | <table> | ||||
<% AdminHelper::SETTINGS.each do |s| %> | <% AdminHelper::SETTINGS.each do |s| %> | ||||
<tr> | <tr> | ||||
<td><%= label_tag(s[:key], s[:label]) %></td> | |||||
<td><%= label_tag("settings[#{s[:key]}]", s[:label]) %></td> | |||||
<% if s[:textarea] %> | <% if s[:textarea] %> | ||||
<td><%= text_area_tag(s[:key], AdminSetting.get(s[:key].to_s), size: "60x5") %></td> | |||||
<td><%= text_area_tag("settings[#{s[:key]}]", AdminSetting.get(s[:key]), size: "60x5") %></td> | |||||
<% else %> | <% else %> | ||||
<td><%= text_field_tag(s[:key], AdminSetting.get(s[:key].to_s), size: 40) %></td> | |||||
<td><%= text_field_tag("settings[#{s[:key]}]", AdminSetting.get(s[:key]), size: 40) %></td> | |||||
<% end %> | <% end %> | ||||
</tr> | </tr> | ||||
<% end %> | <% end %> | ||||
@@ -6,7 +6,7 @@ | |||||
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) | # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) | ||||
# Mayor.create(name: 'Emanuel', city: cities.first) | # Mayor.create(name: 'Emanuel', city: cities.first) | ||||
AdminSetting.create(key: 'site_name', value: 'Your Corporation') | |||||
AdminSetting.create(key: 'site_name', value: 'Your Corporation Site') | |||||
AdminSetting.create(key: 'corporation', value: 'Your Corporation') | AdminSetting.create(key: 'corporation', value: 'Your Corporation') | ||||
AdminSetting.create(key: 'description', value: 'Your corporation\'s description goes here!') | AdminSetting.create(key: 'description', value: 'Your corporation\'s description goes here!') | ||||
AdminSetting.create(key: 'copyright', value: 'Your Corporation/Your Name') | AdminSetting.create(key: 'copyright', value: 'Your Corporation/Your Name') |