Class: ActionDispatch::Routing::Redirect
- Defined in:
 - 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
 - #redirect? ⇒ Boolean
 - #serve(req) ⇒ Object
 
Methods inherited from Endpoint
#app, #dispatcher?, #engine?, #matches?, #rack_app
Constructor Details
#initialize(status, block) ⇒ Redirect
Returns a new instance of Redirect.
      15 16 17 18  | 
    
      # File 'lib/action_dispatch/routing/redirection.rb', line 15 def initialize(status, block) @status = status @block = block end  | 
  
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
      13 14 15  | 
    
      # File 'lib/action_dispatch/routing/redirection.rb', line 13 def block @block end  | 
  
#status ⇒ Object (readonly)
Returns the value of attribute status.
      13 14 15  | 
    
      # File 'lib/action_dispatch/routing/redirection.rb', line 13 def status @status end  | 
  
Instance Method Details
#call(env) ⇒ Object
      22 23 24  | 
    
      # File 'lib/action_dispatch/routing/redirection.rb', line 22 def call(env) serve Request.new env end  | 
  
#inspect ⇒ Object
      58 59 60  | 
    
      # File 'lib/action_dispatch/routing/redirection.rb', line 58 def inspect "redirect(#{status})" end  | 
  
#path(params, request) ⇒ Object
      54 55 56  | 
    
      # File 'lib/action_dispatch/routing/redirection.rb', line 54 def path(params, request) block.call params, request end  | 
  
#redirect? ⇒ Boolean
      20  | 
    
      # File 'lib/action_dispatch/routing/redirection.rb', line 20 def redirect?; true; end  | 
  
#serve(req) ⇒ Object
      26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52  | 
    
      # File 'lib/action_dispatch/routing/redirection.rb', line 26 def serve(req) uri = URI.parse(path(req.path_parameters, req)) unless uri.host if relative_path?(uri.path) uri.path = "#{req.script_name}/#{uri.path}" elsif uri.path.empty? uri.path = req.script_name.empty? ? "/" : req.script_name end end uri.scheme ||= req.scheme uri.host ||= req.host uri.port ||= req.port unless req.standard_port? req.commit_flash body = %(<html><body>You are being <a href="#{ERB::Util.unwrapped_html_escape(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  |