Add admin/pages scaffold and basic page render
This commit is contained in:
1 parent
40831c1314
commit
66604d00f4
12 files changed
+277
-5
No files matched your search
@@ -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>
|
||||
Reference in new issue
Block a user