class Rack::NotFound
Rack::NotFound
is a default endpoint. Optionally initialize with the path to a custom 404 page, to override the standard response body.
Examples:
Serve default 404 response:
run Rack::NotFound.new
Serve a custom 404 page:
run Rack::NotFound.new('path/to/your/404.html')
Constants
- F
Public Class Methods
new(path = nil, content_type = 'text/html')
click to toggle source
# File lib/rack/contrib/not_found.rb 18 def initialize(path = nil, content_type = 'text/html') 19 if path.nil? 20 @content = "Not found\n" 21 else 22 @content = F.read(path) 23 end 24 @length = @content.bytesize.to_s 25 26 @content_type = content_type 27 end
Public Instance Methods
call(env)
click to toggle source
# File lib/rack/contrib/not_found.rb 29 def call(env) 30 [404, {'Content-Type' => @content_type, 'Content-Length' => @length}, [@content]] 31 end