diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 42ebc61..6573eb6 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -1,3 +1,21 @@ class ApplicationController < ActionController::Base session :session_key => '_barleysodas_session_id' -end + + ## + # Sane error and missing document messages. + # + def rescue_action_in_public(exception) + logger.debug("#{exception.class.name}: #{exception.to_s}") + exception.backtrace.each { |bt| logger.debug "! #{bt}" } + case exception + when ::ActiveRecord::RecordNotFound, + ::ActionController::UnknownController, + ::ActionController::UnknownAction, + ::ActionController::RoutingError + render :file => File.join(RAILS_ROOT, 'public/404.html'), + :status => '404 Not Found' + else + render :file => File.join(RAILS_ROOT, 'public/500.html'), + :status => '500 Error' + end + end diff --git a/app/controllers/beers_controller.rb b/app/controllers/beers_controller.rb index 672e97a..a14d272 100644 --- a/app/controllers/beers_controller.rb +++ b/app/controllers/beers_controller.rb @@ -83,6 +83,7 @@ class BeersController < ApplicationController def get_beer_and_page @beer = Beer.find_by_title(Page.title_from_url(params[:id]), :include => [ 'page' ]) + raise ActiveRecord::RecordNotFound.new if @beer.nil? @page = @beer.page end end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index d14b0c7..a25e81f 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -85,5 +85,6 @@ class PagesController < ApplicationController def fetch_page @page = Page.find_by_title(Page.title_from_url(params[:id])) + raise ActiveRecord::RecordNotFound.new if @page.nil? end end