Class: ActionDispatch::Routing::OptionRedirect

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

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from Redirect

#block, #status

Instance Method Summary collapse

Methods inherited from Redirect

#build_response, #call, #initialize, #redirect?

Methods inherited from Endpoint

#app, #dispatcher?, #engine?, #matches?, #rack_app, #redirect?

Constructor Details

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

Instance Method Details

#inspectObject



141
142
143
# File 'actionpack/lib/action_dispatch/routing/redirection.rb', line 141

def inspect
  "redirect(#{status}, #{options.map { |k, v| "#{k}: #{v}" }.join(', ')})"
end

#path(params, request) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'actionpack/lib/action_dispatch/routing/redirection.rb', line 115

def path(params, request)
  url_options = {
    protocol: request.protocol,
    host: request.host,
    port: request.optional_port,
    path: request.path,
    params: request.query_parameters
  }.merge! options

  if !params.empty? && url_options[:path].match(/%\{\w*\}/)
    url_options[:path] = (url_options[:path] % escape_path(params))
  end

  unless options[:host] || options[:domain]
    if relative_path?(url_options[:path])
      url_options[:path] = "/#{url_options[:path]}"
      url_options[:script_name] = request.script_name
    elsif url_options[:path].empty?
      url_options[:path] = request.script_name.empty? ? "/" : ""
      url_options[:script_name] = request.script_name
    end
  end

  ActionDispatch::Http::URL.url_for url_options
end