diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index c2a9ad9..73ac166 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -1,4 +1,9 @@ class AdminController < ApplicationController def index end + + def update + # respond to form data... + render 'index' + end end diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index d5c6d35..16e5a87 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -1,2 +1,8 @@ module AdminHelper + SETTINGS = [ + {:key => :site_name, :label => 'Site name'}, + {:key => :corporation, :label => 'Corporation'}, + {:key => :description, :label => 'Home page description', :textarea => true}, + {:key => :copyright, :label => 'Copyright'}, + ] end diff --git a/app/models/admin_setting.rb b/app/models/admin_setting.rb index 9e4ab4b..668989c 100644 --- a/app/models/admin_setting.rb +++ b/app/models/admin_setting.rb @@ -1,6 +1,16 @@ class AdminSetting < ActiveRecord::Base def self.get(key) - self.find_by(key: key).value + Rails.cache.fetch("admin_setting/#{key}") do + self.find_by(key: key).value + end + end + + def self.set(key, value) + setting = self.find_by(key: key) + setting.update(value: value) + Rails.cache.write("admin_setting/#{key}") do + value + end end end diff --git a/app/views/admin/index.html.erb b/app/views/admin/index.html.erb index 10dadec..34a5e1e 100644 --- a/app/views/admin/index.html.erb +++ b/app/views/admin/index.html.erb @@ -1,4 +1,23 @@ <% provide(:title, 'Admin') %>
Find me in app/views/admin/index.html.erb
+ +<%= link_to 'Home', controller: 'tools', action: 'index' %>
+ +<%= form_tag do %> +<%= label_tag(s[:key], s[:label]) %> | + <% if s[:textarea] %> +<%= text_area_tag(s[:key], AdminSetting.get(s[:key].to_s), size: "60x5") %> | + <% else %> +<%= text_field_tag(s[:key], AdminSetting.get(s[:key].to_s), size: 40) %> | + <% end %> +
<%= submit_tag('Update') %> | +
- Users: - <%= link_to "Signup", controller: "users", action: "create" %> - • - <%= link_to "Login", controller: "users", action: "login" %> + Users: + <%= link_to "Signup", controller: "users", action: "create" %> + • + <%= link_to "Login", controller: "users", action: "login" %>
- Admin: - <%= link_to "Admin", controller: "admin", action: "index" %> + Admin: + <%= link_to "Admin", controller: "admin", action: "index" %>
Tools: ...
diff --git a/config/routes.rb b/config/routes.rb index 5b723ba..9931e04 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,10 +1,11 @@ Rails.application.routes.draw do root 'tools#index' - get '/signup' => 'users#create' - get '/login' => 'users#login' + get '/signup' => 'users#create' + get '/login' => 'users#login' - get '/admin' => 'admin#index' + get '/admin' => 'admin#index' + post '/admin' => 'admin#update' # Example of named route that can be invoked with purchase_url(id: product.id) # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase