Skip to content

Commit 0c02e42

Browse files
committed
Don't use static error pages
* app/controllers/errors_controller.rb: New controller for the various error pages. * app/views/errors/internal_server_error.html.erb: New page for when errors occur. * config/application.rb: * config/routes.rb: Specify that we're using our own routes for errors. * public/404.html: * public/500.html: Remove static error pages.
1 parent 42d512a commit 0c02e42

File tree

6 files changed

+26
-133
lines changed

6 files changed

+26
-133
lines changed

app/controllers/errors_controller.rb

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class ErrorsController < ApplicationController
2+
def internal_server_error
3+
render(status: :internal_server_error)
4+
end
5+
6+
def not_found
7+
render(status: :not_found)
8+
end
9+
10+
def unauthorized
11+
render(status: :unauthorized)
12+
end
13+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div class="alert alert-danger">
2+
An error occurred because something went wrong. Please try again.
3+
</div>
4+
5+
<%= link_to "Main Page", grants_path, class: "btn btn-primary" %>

config/application.rb

+1
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ class Application < Rails::Application
3636
require "environment_setup"
3737
EnvironmentSetup.check_setup
3838
end
39+
config.exceptions_app = routes
3940
end
4041
end

config/routes.rb

+7
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,12 @@
2222
resources :forms
2323
end
2424

25+
match "/401", to: "errors#unauthorized", via: :all
26+
match "/404", to: "errors#not_found", via: :all
27+
match "/500", to: "errors#internal_server_error", via: :all
28+
get 'errors/internal_server_error'
29+
get 'errors/not_found'
30+
get 'errors/unauthorized'
31+
2532
root 'grants#index'
2633
end

public/404.html

-67
This file was deleted.

public/500.html

-66
This file was deleted.

0 commit comments

Comments
 (0)