123456789_123456789_123456789_123456789_123456789_

Class: ActionDispatch::Routing::PathRedirect

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: ActionDispatch::Routing::Redirect
Defined in: actionpack/lib/action_dispatch/routing/redirection.rb

Constant Summary

Class Method Summary

Redirect - Inherited

Instance Attribute Summary

Instance Method Summary

Redirect - Inherited

Endpoint - Inherited

Constructor Details

This class inherits a constructor from ActionDispatch::Routing::Redirect

Instance Method Details

#inspect

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/redirection.rb', line 108

def inspect
  "redirect(#{status}, #{block})"
end

#interpolate_path(template, params) (private)

A decoded param must not give the target a scheme or host that the template lacks, or the redirect would leave the request's host.

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/redirection.rb', line 119

def interpolate_path(template, params)
  path = template % escape_path(params)
  return path if template.match?(SCHEME_OR_AUTHORITY)

  if path.start_with?("//")
    path.sub("//", "/%2F")
  elsif path.match?(SCHEME_OR_AUTHORITY)
    "/#{path.sub(":", "%3A")}"
  else
    path
  end
end

#interpolation_required?(string, params) ⇒ Boolean (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/redirection.rb', line 113

def interpolation_required?(string, params)
  !params.empty? && string && string.match(/%\{\w*\}/)
end

#path(params, request)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/redirection.rb', line 96

def path(params, request)
  if block.match(URL_PARTS)
    path     = interpolation_required?($1, params) ? interpolate_path($1, params) : $1
    query    = interpolation_required?($2, params) ? $2 % escape(params)          : $2
    fragment = interpolation_required?($3, params) ? $3 % escape_fragment(params) : $3

    "#{path}#{query}#{fragment}"
  else
    interpolation_required?(block, params) ? block % escape(params) : block
  end
end