Class: ActionDispatch::Routing::Redirect
- Defined in:
- actionpack/lib/action_dispatch/routing/redirection.rb
Overview
:nodoc:
Direct Known Subclasses
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(status, block) ⇒ Redirect
constructor
A new instance of Redirect.
- #inspect ⇒ Object
- #path(params, request) ⇒ Object
Constructor Details
#initialize(status, block) ⇒ Redirect
Returns a new instance of Redirect.
12 13 14 15 |
# File 'actionpack/lib/action_dispatch/routing/redirection.rb', line 12 def initialize(status, block) @status = status @block = block end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block
10 11 12 |
# File 'actionpack/lib/action_dispatch/routing/redirection.rb', line 10 def block @block end |
#status ⇒ Object (readonly)
Returns the value of attribute status
10 11 12 |
# File 'actionpack/lib/action_dispatch/routing/redirection.rb', line 10 def status @status end |
Instance Method Details
#call(env) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'actionpack/lib/action_dispatch/routing/redirection.rb', line 17 def call(env) req = Request.new(env) # If any of the path parameters has a invalid encoding then # raise since it's likely to trigger errors further on. req.symbolized_path_parameters.each do |key, value| unless value.valid_encoding? raise ActionController::BadRequest, "Invalid parameter: #{key} => #{value}" end end 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 |
#inspect ⇒ Object
48 49 50 |
# File 'actionpack/lib/action_dispatch/routing/redirection.rb', line 48 def inspect "redirect(#{status})" end |
#path(params, request) ⇒ Object
44 45 46 |
# File 'actionpack/lib/action_dispatch/routing/redirection.rb', line 44 def path(params, request) block.call params, request end |