Add admin/pages scaffold and basic page render
This commit is contained in:
parent
40831c1314
commit
66604d00f4
|
@ -0,0 +1,82 @@
|
|||
class Admin::PagesController < ApplicationController
|
||||
# GET /pages
|
||||
# GET /pages.xml
|
||||
def index
|
||||
@pages = Page.all
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.xml { render :xml => @pages }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /pages/1
|
||||
# GET /pages/1.xml
|
||||
def show
|
||||
@page = Page.find(params[:id])
|
||||
|
||||
redirect_to "/#{@page.name}"
|
||||
end
|
||||
|
||||
# GET /pages/new
|
||||
# GET /pages/new.xml
|
||||
def new
|
||||
@page = Page.new
|
||||
|
||||
respond_to do |format|
|
||||
format.html # new.html.erb
|
||||
format.xml { render :xml => @pages }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /pages/1/edit
|
||||
def edit
|
||||
@page = Page.find(params[:id])
|
||||
end
|
||||
|
||||
# POST /pages
|
||||
# POST /pages.xml
|
||||
def create
|
||||
@page = Page.new(params[:page])
|
||||
|
||||
respond_to do |format|
|
||||
if @page.save
|
||||
flash[:notice] = 'Page was successfully created.'
|
||||
format.html { redirect_to admin_pages_url }
|
||||
format.xml { render :xml => @page, :status => :created, :location => @pages }
|
||||
else
|
||||
format.html { render :action => "new" }
|
||||
format.xml { render :xml => @page.errors, :status => :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PUT /pages/1
|
||||
# PUT /pages/1.xml
|
||||
def update
|
||||
@page = Page.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
if @page.update_attributes(params[:page])
|
||||
flash[:notice] = 'Page was successfully updated.'
|
||||
format.html { redirect_to admin_pages_url }
|
||||
format.xml { head :ok }
|
||||
else
|
||||
format.html { render :action => "edit" }
|
||||
format.xml { render :xml => @page.errors, :status => :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /pages/1
|
||||
# DELETE /pages/1.xml
|
||||
def destroy
|
||||
@page = Page.find(params[:id])
|
||||
@page.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to admin_pages_url }
|
||||
format.xml { head :ok }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,14 @@
|
|||
class PagesController < ApplicationController
|
||||
|
||||
def show
|
||||
@page = Page.find_by_name(params[:page_name])
|
||||
|
||||
if @page
|
||||
render :text => @page.content
|
||||
else
|
||||
render :text => '404 not found'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
module PagesHelper
|
||||
end
|
|
@ -0,0 +1,9 @@
|
|||
class Page < CouchFoo::Base
|
||||
|
||||
property :name, String
|
||||
property :parent_name, String
|
||||
property :content, String
|
||||
|
||||
validates_presence_of :name
|
||||
|
||||
end
|
|
@ -0,0 +1,21 @@
|
|||
<h1>Editing pages</h1>
|
||||
|
||||
<% form_for @page, :url => admin_page_path(@page) do |f| %>
|
||||
<%= f.error_messages %>
|
||||
|
||||
<p>
|
||||
<%= f.label :name, "Name" %>
|
||||
<%= f.text_field :name %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.label :content, "Content" %>
|
||||
<%= f.text_area :content %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.submit 'Update' %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<%= link_to 'Back', admin_pages_path %>
|
|
@ -0,0 +1,18 @@
|
|||
<h1>Listing pages</h1>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
</tr>
|
||||
|
||||
<% @pages.each do |page| %>
|
||||
<tr>
|
||||
<td><%= link_to page.name, admin_page_path(page) %></td>
|
||||
<td><%= link_to 'Edit', edit_admin_page_path(page) %></td>
|
||||
<td><%= link_to 'Destroy', admin_page_path(page), :confirm => 'Are you sure?', :method => :delete %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<br />
|
||||
|
||||
<%= link_to 'New pages', new_admin_page_path %>
|
|
@ -0,0 +1,21 @@
|
|||
<h1>New pages</h1>
|
||||
|
||||
<% form_for :page, :url => admin_pages_path do |f| %>
|
||||
<%= f.error_messages %>
|
||||
|
||||
<p>
|
||||
<%= f.label :name, "Name" %>
|
||||
<%= f.text_field :name %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.label :content, "Content" %>
|
||||
<%= f.text_area :content %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.submit 'Create' %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<%= link_to 'Back', admin_pages_path %>
|
|
@ -0,0 +1,17 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
||||
<title>Pages: <%= controller.action_name %></title>
|
||||
<%= stylesheet_link_tag 'scaffold' %>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p style="color: green"><%= flash[:notice] %></p>
|
||||
|
||||
<%= yield %>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,22 @@
|
|||
# SQLite version 3.x
|
||||
# gem install sqlite3-ruby (not necessary on OS X Leopard)
|
||||
development:
|
||||
adapter: sqlite3
|
||||
database: db/development.sqlite3
|
||||
pool: 5
|
||||
timeout: 5000
|
||||
|
||||
# Warning: The database defined as "test" will be erased and
|
||||
# re-generated from your development database when you run "rake".
|
||||
# Do not set this db to the same as development or production.
|
||||
test:
|
||||
adapter: sqlite3
|
||||
database: db/test.sqlite3
|
||||
pool: 5
|
||||
timeout: 5000
|
||||
|
||||
production:
|
||||
adapter: sqlite3
|
||||
database: db/production.sqlite3
|
||||
pool: 5
|
||||
timeout: 5000
|
|
@ -33,9 +33,13 @@ Rails::Initializer.run do |config|
|
|||
|
||||
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
||||
# Run "rake -D time" for a list of tasks for finding time zone names.
|
||||
config.time_zone = 'UTC'
|
||||
config.time_zone = "Taipei"
|
||||
|
||||
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
||||
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
|
||||
# config.i18n.default_locale = :de
|
||||
|
||||
end
|
||||
|
||||
require 'couch_foo'
|
||||
CouchFoo::Base.set_database(:host => "http://localhost:5984", :database => "r4")
|
|
@ -1,4 +1,9 @@
|
|||
ActionController::Routing::Routes.draw do |map|
|
||||
|
||||
map.namespace :admin do |admin|
|
||||
admin.resources :pages
|
||||
end
|
||||
|
||||
# The priority is based upon order of creation: first created -> highest priority.
|
||||
|
||||
# Sample of regular route:
|
||||
|
@ -38,6 +43,9 @@ ActionController::Routing::Routes.draw do |map|
|
|||
# Install the default routes as the lowest priority.
|
||||
# Note: These default routes make all actions in every controller accessible via GET requests. You should
|
||||
# consider removing the them or commenting them out if you're using named routes and resources.
|
||||
map.connect ':controller/:action/:id'
|
||||
map.connect ':controller/:action/:id.:format'
|
||||
|
||||
map.connect ':page_name', :controller => 'pages', :action => 'show'
|
||||
|
||||
#map.connect ':controller/:action/:id'
|
||||
#map.connect ':controller/:action/:id.:format'
|
||||
end
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
body { background-color: #fff; color: #333; }
|
||||
|
||||
body, p, ol, ul, td {
|
||||
font-family: verdana, arial, helvetica, sans-serif;
|
||||
font-size: 13px;
|
||||
line-height: 18px;
|
||||
}
|
||||
|
||||
pre {
|
||||
background-color: #eee;
|
||||
padding: 10px;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
a { color: #000; }
|
||||
a:visited { color: #666; }
|
||||
a:hover { color: #fff; background-color:#000; }
|
||||
|
||||
.fieldWithErrors {
|
||||
padding: 2px;
|
||||
background-color: red;
|
||||
display: table;
|
||||
}
|
||||
|
||||
#errorExplanation {
|
||||
width: 400px;
|
||||
border: 2px solid red;
|
||||
padding: 7px;
|
||||
padding-bottom: 12px;
|
||||
margin-bottom: 20px;
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
|
||||
#errorExplanation h2 {
|
||||
text-align: left;
|
||||
font-weight: bold;
|
||||
padding: 5px 5px 5px 15px;
|
||||
font-size: 12px;
|
||||
margin: -7px;
|
||||
background-color: #c00;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
#errorExplanation p {
|
||||
color: #333;
|
||||
margin-bottom: 0;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
#errorExplanation ul li {
|
||||
font-size: 12px;
|
||||
list-style: square;
|
||||
}
|
||||
|
Reference in New Issue