Skip to content
Browse files

Make :trailing_slash work with query parameters for url_for. Closes #…

…4004 [nov]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7186 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent f9b7394 commit 5476a6a6c7e3be5722481a2bd3b60322f1672c1e @NZKoz NZKoz committed Jul 14, 2007
View
2 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]
View
6 actionpack/lib/action_controller/url_rewriter.rb
@@ -89,9 +89,9 @@ def rewrite_url(options)
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 @@ def rewrite_authentication(options)
end
end
end
-end
+end
View
10 actionpack/test/controller/url_rewriter_test.rb
@@ -73,6 +73,16 @@ def test_to_str
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

0 comments on commit 5476a6a

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