diff options
-rw-r--r-- | actionpack/CHANGELOG | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/url_rewriter.rb | 6 | ||||
-rw-r--r-- | actionpack/test/controller/url_rewriter_test.rb | 10 |
3 files changed, 15 insertions, 3 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 885f318d5d..198e4a2fac 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Make :trailing_slash work with query parameters for url_for. Closes #4004 [nov] + * Make sure missing template exceptions actually say which template they were looking for. Closes #8683 [dasil003] * Fix errors with around_filters which do not yield, restore 1.1 behaviour with after filters. Closes #8891 [skaes] diff --git a/actionpack/lib/action_controller/url_rewriter.rb b/actionpack/lib/action_controller/url_rewriter.rb index 384c818254..3b2af2e1c2 100644 --- a/actionpack/lib/action_controller/url_rewriter.rb +++ b/actionpack/lib/action_controller/url_rewriter.rb @@ -89,9 +89,9 @@ module ActionController rewritten_url << ":#{options.delete(:port)}" if options.key?(:port) end + path = rewrite_path(options) rewritten_url << @request.relative_url_root.to_s unless options[:skip_relative_url_root] - rewritten_url << rewrite_path(options) - rewritten_url << '/' if options[:trailing_slash] + rewritten_url << (options[:trailing_slash] ? path.sub(/\?|\z/) { "/" + $& } : path) rewritten_url << "##{options[:anchor]}" if options[:anchor] rewritten_url @@ -121,4 +121,4 @@ module ActionController end end end -end
\ No newline at end of file +end diff --git a/actionpack/test/controller/url_rewriter_test.rb b/actionpack/test/controller/url_rewriter_test.rb index 1c746b7aee..a49aaa822a 100644 --- a/actionpack/test/controller/url_rewriter_test.rb +++ b/actionpack/test/controller/url_rewriter_test.rb @@ -73,6 +73,16 @@ class UrlRewriterTests < Test::Unit::TestCase assert_equal 'http://, test.host, /, hi, bye, {"id"=>"2"}', @rewriter.to_str end + + def test_trailing_slash + options = {:controller => 'foo', :action => 'bar', :id => '3', :only_path => true} + assert_equal '/foo/bar/3', @rewriter.rewrite(options) + assert_equal '/foo/bar/3?query=string', @rewriter.rewrite(options.merge({:query => 'string'})) + options.update({:trailing_slash => true}) + assert_equal '/foo/bar/3/', @rewriter.rewrite(options) + options.update({:query => 'string'}) + assert_equal '/foo/bar/3/?query=string', @rewriter.rewrite(options) + end end class UrlWriterTests < Test::Unit::TestCase |