Skip to content

Commit

Permalink
Merge pull request #299 from coopdevs/error_pages
Browse files Browse the repository at this point in the history
Custom error pages
  • Loading branch information
sauloperez authored Mar 2, 2018
2 parents 7909293 + 00b0e3c commit 1478aac
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 77 deletions.
12 changes: 12 additions & 0 deletions app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -895,3 +895,15 @@ form .checkbox input[type="checkbox"] {
}
}
}

.errors {
padding: 3em;

h3 {
margin-left: auto;
margin-right: auto;
max-width: 75%;
padding: 1em;
line-height: 1.6em;
}
}
9 changes: 9 additions & 0 deletions app/controllers/errors_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class ErrorsController < ApplicationController
def not_found
render status: 404
end

def internal_server_error
render status: 500
end
end
5 changes: 5 additions & 0 deletions app/views/errors/internal_server_error.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class='text-center errors'>
<h1><%= t('.title') %></h1>
<h3><%= t('.description') %></h3>
<p><%= link_to t('global.home'), root_path, class: 'btn btn-default' %></p>
</div>
5 changes: 5 additions & 0 deletions app/views/errors/not_found.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class='text-center errors'>
<h1><%= t('.title') %></h1>
<h3><%= t('.description') %></h3>
<p><%= link_to t('global.home'), root_path, class: 'btn btn-default' %></p>
</div>
3 changes: 3 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ class Application < Rails::Application

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

# This tells Rails to serve error pages from the app itself, rather than using static error pages in public/
config.exceptions_app = self.routes
end
end
7 changes: 7 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ en:
send_paranoid_instructions: If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.
unlocked: Your account has been unlocked successfully. Please sign in to continue.
errors:
internal_server_error:
title: Internal server error
description: We're sorry, there seems to be an error with this request. A notification has automatically been sent to us, and we will resolve this as soon as possible.
not_found:
title: Not found
description: The page you were looking for doesn't exist. You may have mistyped the address or the page may have moved.
messages:
already_confirmed: was already confirmed, please try signing in
confirmation_period_expired: needs to be confirmed within %{period}, please request a new one
Expand All @@ -289,6 +295,7 @@ en:
edit: Update
filter: Filter
give_time: Time transfer
home: Home
information: Information
locales_header: change language
member_count: 'Number of users:'
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@
end
end

match '/404', to: 'errors#not_found', via: :all
match '/500', to: 'errors#internal_server_error', via: :all
end
26 changes: 0 additions & 26 deletions public/404.html

This file was deleted.

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

This file was deleted.

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

This file was deleted.

0 comments on commit 1478aac

Please sign in to comment.