Skip to content
This repository
Browse code

a leading slash in the :controller of url_for ensures you link to the…

… root namespace
  • Loading branch information...
commit 1915d7ccce99a35c1a5e95e639760168a4bcc99f 1 parent 8a2820a
Xavier Noria fxn authored

Showing 1 changed file with 11 additions and 3 deletions. Show diff stats Hide diff stats

  1. +11 3 actionpack/lib/action_controller/base.rb
14 actionpack/lib/action_controller/base.rb
@@ -549,8 +549,8 @@ def send_response
549 549 response
550 550 end
551 551
552   - # Returns a URL that has been rewritten according to the options hash and the defined Routes.
553   - # (For doing a complete redirect, use redirect_to).
  552 + # Returns a URL that has been rewritten according to the options hash and the defined routes.
  553 + # (For doing a complete redirect, use +redirect_to+).
554 554 #
555 555 # <tt>url_for</tt> is used to:
556 556 #
@@ -590,7 +590,15 @@ def send_response
590 590 # missing values in the current request's parameters. Routes attempts to guess when a value should and should not be
591 591 # taken from the defaults. There are a few simple rules on how this is performed:
592 592 #
593   - # * If the controller name begins with a slash, no defaults are used: <tt>url_for :controller => '/home'</tt>
  593 + # * If the controller name begins with a slash no defaults are used:
  594 + #
  595 + # url_for :controller => '/home'
  596 + #
  597 + # In particular, a leading slash ensures no namespace is assumed. Thus,
  598 + # while <tt>url_for :controller => 'users'</tt> may resolve to
  599 + # <tt>Admin::UsersController</tt> if the current controller lives under
  600 + # that module, <tt>url_for :controller => '/users'</tt> ensures you link
  601 + # to <tt>::UsersController</tt> no matter what.
594 602 # * If the controller changes, the action will default to index unless provided
595 603 #
596 604 # The final rule is applied while the URL is being generated and is best illustrated by an example. Let us consider the

0 comments on commit 1915d7c

Please sign in to comment.
Something went wrong with that request. Please try again.