Actions that fail to perform as expected throw exceptions. These exceptions can either be rescued for the public view (with a nice user-friendly explanation) or for the developers view (with tons of debugging information). The developers view is already implemented by the Action Controller, but the public view should be tailored to your specific application. So too could the decision on whether something is a public or a developer request.
You can tailor the rescuing behavior and appearance by overwriting the following two stub methods.
Overwrite to expand the meaning of a local request in order to show local rescues on other occurences than the remote IP being 127.0.0.1. For example, this could include the IP of the developer machine when debugging remotely.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/rescue.rb, line 61
61: def local_request? #:doc:
62: @request.remote_addr == "127.0.0.1"
63: end
Overwrite to implement custom logging of errors. By default logs as fatal.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/rescue.rb, line 37
37: def log_error(exception) #:doc:
38: if ActionView::TemplateError === exception
39: logger.fatal(exception.to_s)
40: else
41: logger.fatal(
42: "\n\n#{exception.class} (#{exception.message}):\n " +
43: clean_backtrace(exception).join("\n ") +
44: "\n\n"
45: )
46: end
47: end
Overwrite to implement public exception handling (for requests answering false to local_request?).
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/rescue.rb, line 50
50: def rescue_action_in_public(exception) #:doc:
51: case exception
52: when RoutingError, UnknownAction then
53: render_text(IO.read(File.join(RAILS_ROOT, 'public', '404.html')), "404 Not Found")
54: else render_text "<html><body><h1>Application error (Rails)</h1></body></html>"
55: end
56: end