Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 5941

Show
Ignore:
Timestamp:
01/15/07 07:17:58 (2 years ago)
Author:
nzkoz
Message:

Improve the documentation for customising your rescue actions. Closes #7041 [rsanheim]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/lib/action_controller/rescue.rb

    r5771 r5941  
    22  # Actions that fail to perform as expected throw exceptions. These exceptions can either be rescued for the public view 
    33  # (with a nice user-friendly explanation) or for the developers view (with tons of debugging information). The developers view 
    4   # is already implemented by the Action Controller, but the public view should be tailored to your specific application. So too 
    5   # could the decision on whether something is a public or a developer request. 
     4  # is already implemented by the Action Controller, but the public view should be tailored to your specific application.  
     5  #  
     6  # The default behavior for public exceptions is to render a static html file with the name of the error code thrown.  If no such  
     7  # file exists, an empty response is sent with the correct status code. 
    68  # 
    7   # You can tailor the rescuing behavior and appearance by overwriting the following two stub methods. 
     9  # You can override what constitutes a local request by overriding the <tt>local_request?</tt> method in your own controller. 
     10  # Custom rescue behavior is achieved by overriding the <tt>rescue_action_in_public</tt> and <tt>rescue_action_locally</tt> methods. 
    811  module Rescue 
    912    LOCALHOST = '127.0.0.1'.freeze 
     
    7578 
    7679 
    77       # Overwrite to implement public exception handling (for requests answering false to <tt>local_request?</tt>). 
     80      # Overwrite to implement public exception handling (for requests answering false to <tt>local_request?</tt>).  By 
     81      # default will call render_optional_error_file.  Override this method to provide more user friendly error messages.s 
    7882      def rescue_action_in_public(exception) #:doc: 
    7983        render_optional_error_file response_code_for_rescue(exception) 
    8084      end 
    81  
    82       def render_optional_error_file(status_code) #:nodoc: 
     85       
     86      # Attempts to render a static error page based on the <tt>status_code</tt> thrown, 
     87      # or just return headers if no such file exists. For example, if a 500 error is  
     88      # being handled Rails will first attempt to render the file at <tt>public/500.html</tt>.  
     89      # If the file doesn't exist, the body of the response will be left empty 
     90      def render_optional_error_file(status_code) 
    8391        status = interpret_status(status_code) 
    8492        path = "#{RAILS_ROOT}/public/#{status[0,3]}.html"