Class: ActionDispatch::PublicExceptions

Inherits:
Object
  • Object
show all
Defined in:
actionpack/lib/action_dispatch/middleware/public_exceptions.rb

Overview

A simple Rack application that renders exceptions in the given public path.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(public_path) ⇒ PublicExceptions

Returns a new instance of PublicExceptions.



6
7
8
# File 'actionpack/lib/action_dispatch/middleware/public_exceptions.rb', line 6

def initialize(public_path)
  @public_path = public_path
end

Instance Attribute Details

#public_pathObject

Returns the value of attribute public_path



4
5
6
# File 'actionpack/lib/action_dispatch/middleware/public_exceptions.rb', line 4

def public_path
  @public_path
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'actionpack/lib/action_dispatch/middleware/public_exceptions.rb', line 10

def call(env)
  status      = env["PATH_INFO"][1..-1]
  locale_path = "#{public_path}/#{status}.#{I18n.locale}.html" if I18n.locale
  path        = "#{public_path}/#{status}.html"

  if locale_path && File.exist?(locale_path)
    render(status, File.read(locale_path))
  elsif File.exist?(path)
    render(status, File.read(path))
  else
    [404, { "X-Cascade" => "pass" }, []]
  end
end