Skip to content
This repository has been archived by the owner on Jul 21, 2020. It is now read-only.

Commit

Permalink
Fix issue#24 - Add custom messages for HTTP error pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
edmilsonefs authored and hugopl committed May 29, 2015
1 parent f9a5700 commit a9d14ae
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 204 deletions.
4 changes: 0 additions & 4 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ class ApplicationController < ActionController::Base
before_action :authenticate_user!
before_filter :configure_permitted_parameters, if: :devise_controller?

rescue_from ActiveRecord::RecordNotFound do |_exception|
render file: "#{Rails.root}/public/404", layout: false, status: :not_found
end

layout proc { |_controller|
user_signed_in? ? 'application' : 'devise/sessions'
}
Expand Down
13 changes: 13 additions & 0 deletions app/controllers/errors_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class ErrorsController < ApplicationController

def show
render status_code.to_s, :status => status_code
end

protected

def status_code
params[:code] || 500
end

end
4 changes: 4 additions & 0 deletions app/views/errors/404.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="alert alert-danger" role="alert">
<p style="font-size: 48px;"><strong>404 Not Found</strong></p>
<strong>Oops!</strong> The page you requested was not found! <a href="#" onclick="history.back();" class="alert-link">Back to Home</a>.
<div>
4 changes: 4 additions & 0 deletions app/views/errors/422.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="alert alert-danger" role="alert">
<p styke="font-size: 48px;"><strong>422 Unprocessable Entity (WebDAV; RFC 4918)</strong></p>
<strong>Oops!</strong> ... <a href="#" onclick="window.history.back();" class="alert-link">Back to Home</a>.
<div>
4 changes: 4 additions & 0 deletions app/views/errors/500.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="alert alert-danger" role="alert">
<p style="font-size: 48px;"><strong>500 Internal Server Error</strong></p>
<strong>Oops!</strong> An internal error occurred! <a href="#" onclick="history.back();" class="alert-link">Back to Home</a>.
<div>
3 changes: 3 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@ class Application < Rails::Application

# Do not swallow errors in after_commit/after_rollback callbacks.
config.active_record.raise_in_transactional_callbacks = true

# Configure the status code templates to be served by the app instead of Rack exception application.
config.exceptions_app = self.routes
end
end
7 changes: 7 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,11 @@
get :faq, controller: :application

mount Reviewit::API => '/'

# Configure each error code to it's respective action on ErrorsController.
%w( 404 422 500).each do |code|
get code, :to => "errors#show", :code => code
end


end
67 changes: 0 additions & 67 deletions public/404.html

This file was deleted.

67 changes: 0 additions & 67 deletions public/422.html

This file was deleted.

66 changes: 0 additions & 66 deletions public/500.html

This file was deleted.

0 comments on commit a9d14ae

Please sign in to comment.