Created
January 31, 2009 14:26
-
-
Save josevalim/55555 to your computer and use it in GitHub Desktop.
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
# actionpack/lib/action_controller/rescue.rb | |
# | |
module ActionController | |
class Base | |
protected | |
# Attempts to render a static localized error page based on the <tt>status_code</tt> | |
# thrown, or just return headers if no such files exists. For example, if a 500 error | |
# is being handled Rails will first attempt to render the file based on the current | |
# locale such as <tt>public/500.pt-BR.html</tt>. If it does not exist, attempts to | |
# render <tt>public/500.html</tt>. If the files doesn't exist, the body of the response | |
# will be left empty. | |
# | |
def render_optional_error_file(status_code) | |
status = interpret_status(status_code) | |
locale_path = "#{Rails.public_path}/#{status[0,3]}.#{I18n.locale}.html" if I18n.locale | |
path = "#{Rails.public_path}/#{status[0,3]}.html" | |
if locale_path && File.exist?(locale_path) | |
render :file => locale_path, :status => status, :content_type => Mime::HTML | |
elsif File.exist?(path) | |
render :file => path, :status => status, :content_type => Mime::HTML | |
else | |
head status | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment