Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a 'not found' page

  • Loading branch information...
commit 9ebbdac51d7e3ccaa9472020b72118301962d9c4 1 parent 88dd9b0
Gareth Rees authored
View
11 app/controllers/pages_controller.rb
@@ -1,4 +1,6 @@
class PagesController < ApplicationController
+ rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found
+
# GET /pages
# GET /pages.json
def index
@@ -65,6 +67,7 @@ def update
params[:page][:body] = params[:page][:body].gsub(/\<div\>/, '<p>')
params[:page][:body] = params[:page][:body].gsub(/\<\/div\>/, '</p>')
params[:page][:body] = params[:page][:body].gsub(/\<p\>\<br\>\<\/p\>/, '')
+ params[:page][:body] = params[:page][:body].gsub(/\<br\>/, '')
respond_to do |format|
if @page.update_attributes(params[:page])
@@ -89,4 +92,12 @@ def destroy
format.json { head :no_content }
end
end
+
+ private
+
+ def record_not_found
+ @page = params[:id]
+ render :template => "pages/not_found", :status => 404
+ end
+
end
View
22 app/views/pages/index.html.erb
@@ -1,24 +1,10 @@
-<h1>Listing pages</h1>
-
-<table>
- <tr>
- <th>Title</th>
- <th>Body</th>
- <th></th>
- <th></th>
- <th></th>
- </tr>
+<h1>All Pages</h1>
+<ul>
<% @pages.each do |page| %>
- <tr>
- <td><%= page.title %></td>
- <td><%= page.body %></td>
- <td><%= link_to 'Show', page %></td>
- <td><%= link_to 'Edit', edit_page_path(page) %></td>
- <td><%= link_to 'Destroy', page, confirm: 'Are you sure?', method: :delete %></td>
- </tr>
+ <li><%= link_to page.title, page %></li>
<% end %>
-</table>
+</ul>
<br />
View
34 app/views/pages/not_found.html.erb
@@ -0,0 +1,34 @@
+<style type="text/css" media="screen">
+ #toolbar {
+ margin: 10px 1em;
+ }
+ .hidden { display: none; }
+</style>
+
+<p id="notice"><%= notice %></p>
+
+<article class="page">
+
+ <header>
+ <h1><%= @page %></h1>
+ </header>
+
+ <div id="toolbar" class="hidden">
+ <%= link_to 'Bold', "#", id: "bold" %> |
+ <%= link_to 'Italic', "#", id: "italic" %> |
+ <%= link_to 'Link', "#", id: "url" %> |
+ <%= link_to 'Page', "#", id: "insert-page" %>
+ </div>
+
+
+ <div id="page-body" class="body">
+ <p>Click edit to create this page</p>
+ </div>
+
+ <footer>
+ <%= link_to 'Edit', "#", id: "edit-this-page" %> |
+ <%# link_to 'Edit', edit_page_path(@page) %>
+ <%= link_to 'Back', pages_path %>
+ </footer>
+
+</article>
Please sign in to comment.
Something went wrong with that request. Please try again.