Skip to content

Instantly share code, notes, and snippets.

@yuki24
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuki24/10329682 to your computer and use it in GitHub Desktop.
Save yuki24/10329682 to your computer and use it in GitHub Desktop.
Idea for simple and dynamic error page.
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