Class: ActionDispatch::Routing::Redirect

Inherits:
Object
  • Object
show all
Defined in:
actionpack/lib/action_dispatch/routing/redirection.rb

Overview

:nodoc:

Direct Known Subclasses

OptionRedirect

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, block) ⇒ Redirect

Returns a new instance of Redirect.



10
11
12
13
# File 'actionpack/lib/action_dispatch/routing/redirection.rb', line 10

def initialize(status, block)
  @status = status
  @block  = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block



8
9
10
# File 'actionpack/lib/action_dispatch/routing/redirection.rb', line 8

def block
  @block
end

#statusObject (readonly)

Returns the value of attribute status



8
9
10
# File 'actionpack/lib/action_dispatch/routing/redirection.rb', line 8

def status
  @status
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'actionpack/lib/action_dispatch/routing/redirection.rb', line 15

def call(env)
  req = Request.new(env)

  uri = URI.parse(path(req.symbolized_path_parameters, req))
  uri.scheme ||= req.scheme
  uri.host   ||= req.host
  uri.port   ||= req.port unless req.standard_port?

  body = %(<html><body>You are being <a href="#{ERB::Util.h(uri.to_s)}">redirected</a>.</body></html>)

  headers = {
    'Location' => uri.to_s,
    'Content-Type' => 'text/html',
    'Content-Length' => body.length.to_s
  }

  [ status, headers, [body] ]
end

#path(params, request) ⇒ Object



34
35
36
# File 'actionpack/lib/action_dispatch/routing/redirection.rb', line 34

def path(params, request)
  block.call params, request
end