Flowdock
method

url_for

Importance_0
v3.2.13 - Show latest stable - 0 notes - Class: ActionDispatch::Http::URL
url_for(options = {}) public

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File actionpack/lib/action_dispatch/http/url.rb, line 23
        def url_for(options = {})
          unless options[:host].present? || options[:only_path].present?
            raise ArgumentError, 'Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true'
          end

          rewritten_url = ""

          unless options[:only_path]
            unless options[:protocol] == false
              rewritten_url << (options[:protocol] || "http")
              rewritten_url << ":" unless rewritten_url.match(%{:|//})
            end
            rewritten_url << "//" unless rewritten_url.match("//")
            rewritten_url << rewrite_authentication(options)
            rewritten_url << host_or_subdomain_and_domain(options)
            rewritten_url << ":#{options.delete(:port)}" if options[:port]
          end

          path = options.delete(:path) || ''

          params = options[:params] || {}
          params.reject! {|k,v| v.to_param.nil? }

          if options[:trailing_slash] && !path.ends_with?('/')
            rewritten_url << path.sub(/(\?|\z)/) { "/" + $& }
          else
            rewritten_url << path
          end
          rewritten_url << "?#{params.to_query}" unless params.empty?
          rewritten_url << "##{Journey::Router::Utils.escape_fragment(options[:anchor].to_param.to_s)}" if options[:anchor]
          rewritten_url
        end
Register or log in to add new notes.