--- !ruby/object:RI::MethodDescription 
aliases: []

block_params: 
comment: 
- !ruby/struct:SM::Flow::P 
  body: Returns a URL that has been rewritten according to the options hash and the defined routes. (For doing a complete redirect, use <tt>redirect_to</tt>).
- !ruby/struct:SM::Flow::P 
  body: "<tt>url_for</tt> is used to:"
- !ruby/struct:SM::Flow::P 
  body: "All keys given to <tt>url_for</tt> are forwarded to the Route module, save for the following:"
- !ruby/object:SM::Flow::LIST 
  contents: 
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:anchor</tt> - Specifies the anchor name to be appended to the path. For example, <tt>url_for :controller =&gt; 'posts', :action =&gt; 'show', :id =&gt; 10, :anchor =&gt; 'comments'</tt> will produce &quot;/posts/show/10#comments&quot;.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:only_path</tt> - If true, returns the relative URL (omitting the protocol, host name, and port) (<tt>false</tt> by default).
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:trailing_slash</tt> - If true, adds a trailing slash, as in &quot;/archive/2005/&quot;. Note that this is currently not recommended since it breaks caching.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:host</tt> - Overrides the default (current) host if provided.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:protocol</tt> - Overrides the default (current) protocol if provided.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:port</tt> - Optionally specify the port to connect to.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:user</tt> - Inline HTTP authentication (only plucked out if <tt>:password</tt> is also present).
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:password</tt> - Inline HTTP authentication (only plucked out if <tt>:user</tt> is also present).
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:skip_relative_url_root</tt> - If true, the url is not constructed using the <tt>relative_url_root</tt> of the request so the path will include the web server relative installation directory.
  type: :BULLET
- !ruby/struct:SM::Flow::P 
  body: "The URL is generated from the remaining keys in the hash. A URL contains two key parts: the &lt;base&gt; and a query string. Routes composes a query string as the key/value pairs not included in the &lt;base&gt;."
- !ruby/struct:SM::Flow::P 
  body: "The default Routes setup supports a typical Rails path of &quot;controller/action/id&quot; where action and id are optional, with action defaulting to 'index' when not given. Here are some typical url_for statements and their corresponding URLs:"
- !ruby/struct:SM::Flow::VERB 
  body: "  url_for :controller =&gt; 'posts', :action =&gt; 'recent'                # =&gt; 'proto://host.com/posts/recent'\n  url_for :controller =&gt; 'posts', :action =&gt; 'index'                 # =&gt; 'proto://host.com/posts'\n  url_for :controller =&gt; 'posts', :action =&gt; 'index', :port=&gt;'8033'  # =&gt; 'proto://host.com:8033/posts'\n  url_for :controller =&gt; 'posts', :action =&gt; 'show', :id =&gt; 10       # =&gt; 'proto://host.com/posts/show/10'\n  url_for :controller =&gt; 'posts', :user =&gt; 'd', :password =&gt; '123'   # =&gt; 'proto://d:123@host.com/posts'\n"
- !ruby/struct:SM::Flow::P 
  body: "When generating a new URL, missing values may be filled in from the current request's parameters. For example, <tt>url_for :action =&gt; 'some_action'</tt> will retain the current controller, as expected. This behavior extends to other parameters, including <tt>:controller</tt>, <tt>:id</tt>, and any other parameters that are placed into a Route's path. \xC2\xA0 The URL helpers such as <tt>url_for</tt> have a limited form of memory: when generating a new URL, they can look for missing values in the current request's parameters. Routes attempts to guess when a value should and should not be taken from the defaults. There are a few simple rules on how this is performed:"
- !ruby/object:SM::Flow::LIST 
  contents: 
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: "If the controller name begins with a slash no defaults are used:"
  - !ruby/struct:SM::Flow::VERB 
    body: "  url_for :controller =&gt; '/home'\n"
  - !ruby/struct:SM::Flow::P 
    body: In particular, a leading slash ensures no namespace is assumed. Thus, while <tt>url_for :controller =&gt; 'users'</tt> may resolve to <tt>Admin::UsersController</tt> if the current controller lives under that module, <tt>url_for :controller =&gt; '/users'</tt> ensures you link to <tt>::UsersController</tt> no matter what.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: If the controller changes, the action will default to index unless provided
  type: :BULLET
- !ruby/struct:SM::Flow::P 
  body: The final rule is applied while the URL is being generated and is best illustrated by an example. Let us consider the route given by <tt>map.connect 'people/:last/:first/:action', :action =&gt; 'bio', :controller =&gt; 'people'</tt>.
- !ruby/struct:SM::Flow::P 
  body: Suppose that the current URL is &quot;people/hh/david/contacts&quot;. Let's consider a few different cases of URLs which are generated from this page.
- !ruby/object:SM::Flow::LIST 
  contents: 
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>url_for :action =&gt; 'bio'</tt> -- During the generation of this URL, default values will be used for the first and
  type: :BULLET
- !ruby/struct:SM::Flow::P 
  body: last components, and the action shall change. The generated URL will be, &quot;people/hh/david/bio&quot;.
- !ruby/object:SM::Flow::LIST 
  contents: 
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>url_for :first =&gt; 'davids-little-brother'</tt> This generates the URL 'people/hh/davids-little-brother' -- note that this URL leaves out the assumed action of 'bio'.
  type: :BULLET
- !ruby/struct:SM::Flow::P 
  body: "However, you might ask why the action from the current request, 'contacts', isn't carried over into the new URL. The answer has to do with the order in which the parameters appear in the generated path. In a nutshell, since the value that appears in the slot for <tt>:first</tt> is not equal to default value for <tt>:first</tt> we stop using defaults. On its own, this rule can account for much of the typical Rails URL behavior. \xC2\xA0 Although a convenience, defaults can occasionally get in your way. In some cases a default persists longer than desired. The default may be cleared by adding <tt>:name =&gt; nil</tt> to <tt>url_for</tt>'s options. This is often required when writing form helpers, since the defaults in play may vary greatly depending upon where the helper is used from. The following line will redirect to PostController's default action, regardless of the page it is displayed on:"
- !ruby/struct:SM::Flow::VERB 
  body: "  url_for :controller =&gt; 'posts', :action =&gt; nil\n"
- !ruby/struct:SM::Flow::P 
  body: If you explicitly want to create a URL that's almost the same as the current URL, you can do so using the <tt>:overwrite_params</tt> options. Say for your posts you have different views for showing and printing them. Then, in the show view, you get the URL for the print view like this
- !ruby/struct:SM::Flow::VERB 
  body: "  url_for :overwrite_params =&gt; { :action =&gt; 'print' }\n"
- !ruby/struct:SM::Flow::P 
  body: This takes the current URL as is and only exchanges the action. In contrast, <tt>url_for :action =&gt; 'print'</tt> would have slashed-off the path components after the changed action.
full_name: ActionController::Base#url_for
is_singleton: false
name: url_for
params: (options = {})
visibility: public
