From 3280a6e51b6359095000d810c9fe2d3d8c6ac352 Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Fri, 17 Aug 2007 01:08:16 +0000 Subject: Improve url_for documentation for ActionController::Base and UrlRewriter. Closes #9022. Closes #9077. [juanjo.bazan] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7331 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/base.rb | 22 ++++++++++++--------- actionpack/lib/action_controller/url_rewriter.rb | 25 ++++++++++++++++++------ 2 files changed, 32 insertions(+), 15 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index da948940af..353f3f7330 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -514,21 +514,25 @@ module ActionController #:nodoc: # * :only_path -- if true, returns the relative URL (omitting the protocol, host name, and port) (false by default) # * :trailing_slash -- if true, adds a trailing slash, as in "/archive/2005/". Note that this # is currently not recommended since it breaks caching. - # * :host -- overrides the default (current) host if provided - # * :protocol -- overrides the default (current) protocol if provided - # * :user -- Inline HTTP authentication (only plucked out if :password is also present) - # * :password -- Inline HTTP authentication (only plucked out if :user is also present) + # * :host -- overrides the default (current) host if provided. + # * :protocol -- overrides the default (current) protocol if provided. + # * :port -- optionally specify the port to connect to. + # * :user -- Inline HTTP authentication (only plucked out if :password is also present). + # * :password -- Inline HTTP authentication (only plucked out if :user is also present). + # * :skip_relative_url_root -- if true, the url is not constructed using the relative_url_root of the request so the path + # will include the web server relative installation directory. # # The URL is generated from the remaining keys in the hash. A URL contains two key parts: the and a query string. # Routes composes a query string as the key/value pairs not included in the . # # The default Routes setup supports a typical Rails path of "controller/action/id" 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: - #   - # url_for :controller => 'posts', :action => 'recent' # => 'proto://host.com/posts/recent' - # url_for :controller => 'posts', :action => 'index' # => 'proto://host.com/posts' - # url_for :controller => 'posts', :action => 'show', :id => 10 # => 'proto://host.com/posts/show/10' - # url_for :controller => 'posts', :user => 'd', :password => '123' # => 'proto://d:123@host.com/posts' + # + # url_for :controller => 'posts', :action => 'recent' # => 'proto://host.com/posts/recent' + # url_for :controller => 'posts', :action => 'index' # => 'proto://host.com/posts' + # url_for :controller => 'posts', :action => 'index', :port=>'8033' # => 'proto://host.com:8033/posts' + # url_for :controller => 'posts', :action => 'show', :id => 10 # => 'proto://host.com/posts/show/10' + # url_for :controller => 'posts', :user => 'd', :password => '123' # => 'proto://d:123@host.com/posts' # # When generating a new URL, missing values may be filled in from the current request's parameters. For example, # url_for :action => 'some_action' will retain the current controller, as expected. This behavior extends to diff --git a/actionpack/lib/action_controller/url_rewriter.rb b/actionpack/lib/action_controller/url_rewriter.rb index 3b2af2e1c2..0ed6e4de7d 100644 --- a/actionpack/lib/action_controller/url_rewriter.rb +++ b/actionpack/lib/action_controller/url_rewriter.rb @@ -26,13 +26,26 @@ module ActionController base.default_url_options ||= default_url_options end - # Generate a url with the provided options. The following special options may - # effect the constructed url: + # Generate a url based on the options provided, default_url_options and the + # routes defined in routes.rb + # + # Options used by url_for: + # + # * :only_path If true, the relative url is returned. Defaults to false. + # * :protocol The protocol to connect to. Defaults to 'http'. + # * :host Specifies the host the link should be targetted at. If :only_path is false, this option must be + # provided either explicitly, or via default_url_options. + # * :port Optionally specify the port to connect to. + # * :anchor An anchor name to be appended to the path. + # + # Any other key(:controller, :action, etc...) given to url_for is forwarded to the Routes module. + # + # Examples: + # + # url_for :controller => 'tasks', :action => 'testing', :host=>'somehost.org', :port=>'8080' # => 'http://somehost.org:8080/tasks/testing' + # url_for :controller => 'tasks', :action => 'testing', :host=>'somehost.org', :anchor => 'ok', :only_path => true # => '/tasks/testing#ok' + # url_for :controller => 'tasks', :action => 'testing', :host=>'somehost.org', :number => '33' # => 'http://somehost.org/tasks/testing?number=33' # - # * :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. def url_for(options) options = self.class.default_url_options.merge(options) -- cgit v1.2.3