Browse Source

Cache admin settings; work on admin functionality.

old-ruby
Ben Kurtovic 9 years ago
parent
commit
ee71a3972d
9 changed files with 70 additions and 29 deletions
  1. +5
    -0
      app/controllers/admin_controller.rb
  2. +6
    -0
      app/helpers/admin_helper.rb
  3. +11
    -1
      app/models/admin_setting.rb
  4. +20
    -1
      app/views/admin/index.html.erb
  5. +10
    -10
      app/views/layouts/application.html.erb
  6. +7
    -7
      app/views/shared/_footer.html.erb
  7. +1
    -1
      app/views/shared/_header.html.erb
  8. +6
    -6
      app/views/tools/index.html.erb
  9. +4
    -3
      config/routes.rb

+ 5
- 0
app/controllers/admin_controller.rb View File

@@ -1,4 +1,9 @@
class AdminController < ApplicationController
def index
end

def update
# respond to form data...
render 'index'
end
end

+ 6
- 0
app/helpers/admin_helper.rb View File

@@ -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

+ 11
- 1
app/models/admin_setting.rb View File

@@ -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

+ 20
- 1
app/views/admin/index.html.erb View File

@@ -1,4 +1,23 @@
<% provide(:title, 'Admin') %>

<h1>Admin#index</h1>
<p>Find me in app/views/admin/index.html.erb</p>

<p><%= link_to 'Home', controller: 'tools', action: 'index' %></p>

<%= form_tag do %>
<table>
<% AdminHelper::SETTINGS.each do |s| %>
<tr>
<td><%= label_tag(s[:key], s[:label]) %></td>
<% if s[:textarea] %>
<td><%= text_area_tag(s[:key], AdminSetting.get(s[:key].to_s), size: "60x5") %></td>
<% else %>
<td><%= text_field_tag(s[:key], AdminSetting.get(s[:key].to_s), size: 40) %></td>
<% end %>
</tr>
<% end %>
<tr>
<td colspan="2"><%= submit_tag('Update') %></td>
</tr>
</table>
<% end %>

+ 10
- 10
app/views/layouts/application.html.erb View File

@@ -1,17 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<title><%= get_title(yield(:title)) %></title>
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag 'application' %>
<%= csrf_meta_tags %>
<title><%= get_title(yield(:title)) %></title>
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag 'application' %>
<%= csrf_meta_tags %>
</head>
<body>
<%= render "shared/header" %>
</div>
<div id="content">
<%= yield %>
</div>
<%= render "shared/footer" %>
<%= render "shared/header" %>
</div>
<div id="content">
<%= yield %>
</div>
<%= render "shared/footer" %>
</body>
</html>

+ 7
- 7
app/views/shared/_footer.html.erb View File

@@ -1,9 +1,9 @@
<div id="footer">
<p>
Copyright &copy; <%= get_copyright_year %> <%= get_copyright_holders %>
&bull;
Running Calefaction <%= Calefaction::Version::VERSION_STRING %>
&bull;
<a href="//eveonline.com">EVE Online</a> and all related trademarks are property of <a href="//ccpgames.com">CCP hf</a>.
</p>
<p>
Copyright &copy; <%= get_copyright_year %> <%= get_copyright_holders %>
&bull;
Running Calefaction <%= Calefaction::Version::VERSION_STRING %>
&bull;
<a href="//eveonline.com">EVE Online</a> and all related trademarks are property of <a href="//ccpgames.com">CCP hf</a>.
</p>
</div>

+ 1
- 1
app/views/shared/_header.html.erb View File

@@ -1,3 +1,3 @@
<div id="header">
<!-- -->
<!-- -->
</div>

+ 6
- 6
app/views/tools/index.html.erb View File

@@ -1,14 +1,14 @@
<h1>Tools#index</h1>

<p>
Users:
<%= link_to "Signup", controller: "users", action: "create" %>
&bull;
<%= link_to "Login", controller: "users", action: "login" %>
Users:
<%= link_to "Signup", controller: "users", action: "create" %>
&bull;
<%= link_to "Login", controller: "users", action: "login" %>
</p>
<p>
Admin:
<%= link_to "Admin", controller: "admin", action: "index" %>
Admin:
<%= link_to "Admin", controller: "admin", action: "index" %>
</p>
<p>Tools: ...</p>



+ 4
- 3
config/routes.rb View File

@@ -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


Loading…
Cancel
Save