Skip to content

Custom error pages #299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.