- D
- E
- H
- O
- P
- R
- S
- U
# File actionpack/lib/action_dispatch/http/url.rb, line 23 23: def url_for(options = {}) 24: unless options[:host].present? || options[:only_path].present? 25: raise ArgumentError, 'Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true' 26: end 27: 28: rewritten_url = "" 29: 30: unless options[:only_path] 31: unless options[:protocol] == false 32: rewritten_url << (options[:protocol] || "http") 33: rewritten_url << ":" unless rewritten_url.match(%r{:|//}) 34: end 35: rewritten_url << "//" unless rewritten_url.match("//") 36: rewritten_url << rewrite_authentication(options) 37: rewritten_url << host_or_subdomain_and_domain(options) 38: rewritten_url << ":#{options.delete(:port)}" if options[:port] 39: end 40: 41: path = options.delete(:path) || '' 42: 43: params = options[:params] || {} 44: params.reject! {|k,v| v.to_param.nil? } 45: 46: rewritten_url << (options[:trailing_slash] ? path.sub(/\?|\z/) { "/" + $& } : path) 47: rewritten_url << "?#{params.to_query}" unless params.empty? 48: rewritten_url << "##{Journey::Router::Utils.escape_fragment(options[:anchor].to_param.to_s)}" if options[:anchor] 49: rewritten_url 50: end
Returns the domain part of a host, such as “rubyonrails.org“ in “www.rubyonrails.org“. You can specify a different tld_length, such as 2 to catch rubyonrails.co.uk in “www.rubyonrails.co.uk“.
Returns the host for this request, such as example.com.
Returns a host:port string for this request, such as “example.com“ or “example.com:8080”.
Returns a number port suffix like 8080 if the port number of this request is not the default HTTP port 80 or HTTPS port 443.
Returns the port number of this request as an integer.
Returns a string port suffix, including colon, like “:8080” if the port number of this request is not the default HTTP port 80 or HTTPS port 443.
Returns ‘https://’ if this is an SSL request and ‘http://’ otherwise.
Returns the host for this request, such as “example.com“.
# File actionpack/lib/action_dispatch/http/url.rb, line 92 92: def raw_host_with_port 93: if forwarded = env["HTTP_X_FORWARDED_HOST"] 94: forwarded.split(/,\s?/).last 95: else 96: env['HTTP_HOST'] || "#{env['SERVER_NAME'] || env['SERVER_ADDR']}:#{env['SERVER_PORT']}" 97: end 98: end
Returns the standard port number for this request’s protocol.
Returns whether this request is using the standard port
Returns all the subdomains as a string, so "dev.www" would be returned for “dev.www.rubyonrails.org“. You can specify a different tld_length, such as 2 to catch "www" instead of "www.rubyonrails" in “www.rubyonrails.co.uk“.
Returns all the subdomains as an array, so ["dev", "www"] would be returned for “dev.www.rubyonrails.org“. You can specify a different tld_length, such as 2 to catch ["www"] instead of ["www", "rubyonrails"] in “www.rubyonrails.co.uk“.