Skip to content

Instantly share code, notes, and snippets.

@blakerego
Last active December 16, 2015 10:49
Show Gist options
  • Save blakerego/5422906 to your computer and use it in GitHub Desktop.
Save blakerego/5422906 to your computer and use it in GitHub Desktop.
ruby_rails_404_handling
...
include ErrorsHelper
rescue_from ActionController::RoutingError, ActionController::UnknownController, ::AbstractController::ActionNotFound, ActiveRecord::RecordNotFound, with: lambda { |exception| render_error 404, exception }
...
class ErrorsController < ApplicationController
def not_found
end
end
module ErrorsHelper
def render_error(status_code, exception)
render :template => "errors/not_found", :status => 404, :layout => "application"
true # so we can do "render_404 and return"
end
end
#message
Sorry. The page you are looking for cannot be found.
match '*rest', :to => 'errors#not_found'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment