instance method render_optional_error_file

Ruby on Rails 2.3.18

Since v2.2.3 Last seen in v2.3.18

Available in: v2.2.3 v2.3.18

Signature

render_optional_error_file(status_code)

Attempts to render a static error page based on the status_code thrown, or just return headers if no such file exists. At first, it will try to render a localized static page. For example, if a 500 error is being handled Rails and locale is :da, it will first attempt to render the file at public/500.da.html then attempt to render public/500.html. If none of them exist, the body of the response will be left empty.

Parameters

status_code req
Source
# File actionpack/lib/action_controller/rescue.rb, line 107
      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

Defined in actionpack/lib/action_controller/rescue.rb line 107 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActionController::Rescue

Type at least 2 characters to search.

↑↓ navigate · open · esc close