url_for(options)
public
Generate a url with the provided options. The following special options may
effect the constructed url:
* :host Specifies the host the link should be targetted at. This option
must be provided either explicitly, or via default_url_options.
* :protocol The protocol to connect to. Defaults to 'http'
* :port Optionally specify the port to connect to.
# File actionpack/lib/action_controller/url_rewriter.rb, line 40
def url_for(options)
options = self.class.default_url_options.merge(options)
url = ''
unless options.delete :only_path
url << (options.delete(:protocol) || 'http')
url << '://'
raise "Missing host to link to! Please provide :host parameter or set default_url_options[:host]" unless options[:host]
url << options.delete(:host)
url << ":#{options.delete(:port)}" if options.key?(:port)
else
# Delete the unused options to prevent their appearance in the query string
[:protocol, :host, :port].each { |k| options.delete k }
end
anchor = "##{options.delete(:anchor)}" if options.key?(:anchor)
url << Routing::Routes.generate(options, {})
return "#{url}#{anchor}"
end