From 7a6a923f983a2d642a4efd4e962b4385987e167a Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 26 Mar 2005 13:38:21 +0000 Subject: Added trailing_slash option to url_for, so you can generate urls ending in a slash. Note that is currently not recommended unless you need it for special reasons since it breaks caching #937 [stian@grytoyr.net] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1001 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/base.rb | 2 ++ actionpack/lib/action_controller/url_rewriter.rb | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index a0c1bb2e2e..ba0feef98e 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -343,6 +343,8 @@ module ActionController #:nodoc: # url_for :controller => 'posts', :action => 'show', :id => 10, :anchor => 'comments' # will produce "/posts/show/10#comments". # * :only_path -- if true, returns the absolute URL (omitting the protocol, host name, and port) + # * :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 # diff --git a/actionpack/lib/action_controller/url_rewriter.rb b/actionpack/lib/action_controller/url_rewriter.rb index 89245ceb37..8328de7e4f 100644 --- a/actionpack/lib/action_controller/url_rewriter.rb +++ b/actionpack/lib/action_controller/url_rewriter.rb @@ -2,7 +2,7 @@ module ActionController # Rewrites URLs for Base.redirect_to and Base.url_for in the controller. class UrlRewriter #:nodoc: - RESERVED_OPTIONS = [:anchor, :params, :only_path, :host, :protocol] + RESERVED_OPTIONS = [:anchor, :params, :only_path, :host, :protocol, :trailing_slash] def initialize(request, parameters) @request, @parameters = request, parameters end @@ -26,6 +26,7 @@ module ActionController rewritten_url << @request.relative_url_root.to_s rewritten_url << path + rewritten_url << '/' if options[:trailing_slash] rewritten_url << "##{options[:anchor]}" if options[:anchor] return rewritten_url -- cgit v1.2.3