Skip to content

Commit e8e7b66

Browse files
committed
Add custom 404 & 500 pages
1 parent 109f424 commit e8e7b66

File tree

5 files changed

+26
-0
lines changed

5 files changed

+26
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class ErrorsController < ApplicationController
2+
def not_found
3+
respond_to do |format|
4+
format.html { render status: 404 }
5+
format.json { render json: {'message': "This page does not exist."} }
6+
end
7+
end
8+
9+
def internal_server_error
10+
respond_to do |format|
11+
format.html { render status: 500 }
12+
format.json { render json: {'message': "An unexpected error has occurred. We have received the error report and will be addressing it promptly."} }
13+
end
14+
end
15+
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<% alert_tag class: 'alert-danger' do %>
2+
<strong>Oh No! </strong> An unexpected error has occurred. We have received the error report and will be addressing it promptly.
3+
<% end %>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<% alert_tag class: 'alert-danger' do %>
2+
<strong>Oh No! </strong> This page does not exist.
3+
<% end %>

config/application.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Application < Rails::Application
1313
config.load_defaults 7.0
1414
config.time_zone = "Taipei"
1515
config.site_name = "TIOJ INFOR Online Judge"
16+
config.exceptions_app = self.routes
1617
begin
1718
config.x.settings = config_for(:settings)
1819
if !config.x.settings

config/routes.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,9 @@
130130
# You can have the root of your site routed with "root"
131131
root 'welcome#index'
132132

133+
# Custom error pages
134+
match '/404', to: 'errors#not_found', via: :all
135+
match '/500', to: 'errors#internal_server_error', via: :all
136+
133137
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
134138
end

0 commit comments

Comments
 (0)