From 95e8f02478867a5e360860fa796072d579a6f4da Mon Sep 17 00:00:00 2001 From: albert Date: Fri, 15 Mar 2013 15:18:43 -0400 Subject: [PATCH] handle some common error cases --- app/controllers/application_controller.rb | 4 ++++ app/controllers/comment_votes_controller.rb | 1 + app/controllers/posts_controller.rb | 1 + app/controllers/wiki_pages_controller.rb | 7 ++++++- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f0dad4e10..58f74acf0 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -18,6 +18,10 @@ protected @exception = nil @error_message = "The database timed out running your query." render :template => "static/error", :status => 500 + elsif exception.is_a?(::ActiveRecord::RecordNotFound) + @exception = nil + @error_message = "That record was not found", :status => 404 + render :template => "static/error", :status => 500 else render :template => "static/error", :status => 500 end diff --git a/app/controllers/comment_votes_controller.rb b/app/controllers/comment_votes_controller.rb index 6e00f63b6..f1702021e 100644 --- a/app/controllers/comment_votes_controller.rb +++ b/app/controllers/comment_votes_controller.rb @@ -1,5 +1,6 @@ class CommentVotesController < ApplicationController respond_to :js + before_filter :member_only def create @comment = Comment.find(params[:comment_id]) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index fe2ffd604..a72d35132 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -5,6 +5,7 @@ class PostsController < ApplicationController rescue_from PostSets::SearchError, :with => :rescue_exception rescue_from Post::SearchError, :with => :rescue_exception rescue_from ActiveRecord::StatementInvalid, :with => :rescue_exception + rescue_from ActiveRecord::RecordNotFound, :with => :rescue_exception def index @post_set = PostSets::Post.new(tag_query, params[:page], params[:limit]) diff --git a/app/controllers/wiki_pages_controller.rb b/app/controllers/wiki_pages_controller.rb index 6a5db5ae9..63775b070 100644 --- a/app/controllers/wiki_pages_controller.rb +++ b/app/controllers/wiki_pages_controller.rb @@ -3,6 +3,7 @@ class WikiPagesController < ApplicationController before_filter :member_only, :except => [:index, :show, :show_or_new] before_filter :moderator_only, :only => [:destroy] before_filter :normalize_search_params, :only => [:index] + rescue_from ActiveRecord::StatementInvalid, :with => :rescue_exception def new @wiki_page = WikiPage.new(params[:wiki_page]) @@ -26,7 +27,11 @@ class WikiPagesController < ApplicationController end def show - @wiki_page = WikiPage.find(params[:id]) + if params[:id] =~ /[a-zA-Z]/ + @wiki_page = WikiPage.find_by_title(params[:id]) + else + @wiki_page = WikiPage.find(params[:id]) + end respond_with(@wiki_page) end