From 6a66dcca2d9345b7634bcf61f341cfac629e1e2b Mon Sep 17 00:00:00 2001 From: joshua stein Date: Mon, 17 Apr 2017 12:19:41 -0500 Subject: [PATCH] add a dynamic 404 page --- .gitignore | 1 + app/controllers/home_controller.rb | 19 ++++++++++++++++--- config/application.rb | 2 ++ config/routes.rb | 2 ++ public/404.html | 9 --------- 5 files changed, 21 insertions(+), 12 deletions(-) delete mode 100644 public/404.html diff --git a/.gitignore b/.gitignore index b17eeb83..4758e1a7 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ public/assets app/views/home/privacy.* app/views/home/about.* app/views/home/chat.* +app/views/home/404.* app/assets/stylesheets/local/* public/favicon.ico public/apple-touch-icon* diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index a195d06b..44b7209c 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -4,11 +4,23 @@ class HomeController < ApplicationController before_filter { @page = page } before_filter :require_logged_in_user, :only => [ :upvoted ] + def four_oh_four + begin + @title = "Resource Not Found" + render :action => "404", :status => 404 + rescue ActionView::MissingTemplate + render :text => "
" << + "
404
" << + "Resource not found" << + "
", :layout => "application" + end + end + def about begin @title = "About" render :action => "about" - rescue + rescue ActionView::MissingTemplate render :text => "
" << "A mystery." << "
", :layout => "application" @@ -19,8 +31,9 @@ class HomeController < ApplicationController begin @title = "Chat" render :action => "chat" - rescue + rescue ActionView::MissingTemplate render :text => "
" << + "
Chat
" << "Keep it on-site" << "
", :layout => "application" end @@ -30,7 +43,7 @@ class HomeController < ApplicationController begin @title = "Privacy" render :action => "privacy" - rescue + rescue ActionView::MissingTemplate render :text => "
" << "You apparently have no privacy." << "
", :layout => "application" diff --git a/config/application.rb b/config/application.rb index f72ae951..f7a0368a 100644 --- a/config/application.rb +++ b/config/application.rb @@ -30,6 +30,8 @@ module Lobsters config.cache_store = :file_store, "#{config.root}/tmp/cache/" + config.exceptions_app = self.routes + config.after_initialize do require "#{Rails.root}/lib/monkey.rb" end diff --git a/config/routes.rb b/config/routes.rb index 4f8bda7f..c0e29949 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,6 +4,8 @@ Lobsters::Application.routes.draw do :protocol => (Rails.application.config.force_ssl ? "https://" : "http://"), :as => "root" + get "/404" => "home#four_oh_four", :via => :all + get "/rss" => "home#index", :format => "rss" get "/hottest" => "home#index", :format => "json" diff --git a/public/404.html b/public/404.html deleted file mode 100644 index 86724f74..00000000 --- a/public/404.html +++ /dev/null @@ -1,9 +0,0 @@ - - - - 404 - - -

gone fishin'

- -