Last active
August 29, 2015 13:58
-
-
Save yuki24/10329682 to your computer and use it in GitHub Desktop.
Idea for simple and dynamic error page.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ErrorPages < Ambulance::App | |
# idea 0: rails' rescue_from | |
rescue_from CanCan::AccessDenied, ActiveRecord::NotFound, ActionController::RoutingError do |exception| | |
render file: 'public/404.html', status: :not_found, layout: false | |
end | |
# idea 1: | |
routes ActiveRecord::NotFound, | |
ActionController::RoutingError, to: 404 | |
# or you can also use symbol. | |
routes ActiveRecord::NotFound, | |
ActionController::RoutingError, to: :not_found | |
routes CanCan::AccessDenied, to: :unauthorized | |
routes StandardError, to: :internal_server_error | |
# idea 2: | |
map :not_found, | |
ActiveRecord::NotFound, ActionController::RoutingError | |
map :unauthorized, | |
CanCan::AccessDenied | |
map :internal_server_error, StandardError | |
handle :not_found do |exception| | |
render file: "public/404.html" | |
end | |
handle :internal_server_error do |exception| | |
render file: "public/500.html" | |
end | |
# or give a block directly(applicable to both). | |
map :not_found, exceptions do | |
render file: "public/404.html" | |
end | |
routes exceptions, to: :not_found do | |
render file: "public/404.html" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment