From 5a3bb880db43f7bfba3a2838841baaff3d9050af Mon Sep 17 00:00:00 2001 From: Nicholas Seckar Date: Wed, 2 May 2007 04:40:33 +0000 Subject: Update UrlWriter to accept :anchor parameter. Closes #6771. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6648 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 2 ++ actionpack/lib/action_controller/url_rewriter.rb | 2 ++ actionpack/test/controller/url_rewriter_test.rb | 13 +++++++++++++ 3 files changed, 17 insertions(+) (limited to 'actionpack') diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 6142b42c0d..f4fdeaa76d 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Update UrlWriter to accept :anchor parameter. Closes #6771. [octopod] + * Added RecordTagHelper for using RecordIdentifier conventions on divs and other container elements [DHH]. Example: <% div_for(post) do %>
diff --git a/actionpack/lib/action_controller/url_rewriter.rb b/actionpack/lib/action_controller/url_rewriter.rb index 88c7afff41..636fe55f97 100644 --- a/actionpack/lib/action_controller/url_rewriter.rb +++ b/actionpack/lib/action_controller/url_rewriter.rb @@ -51,7 +51,9 @@ module ActionController [:protocol, :host, :port].each { |k| options.delete k } end + anchor = "##{CGI.escape options.delete(:anchor).to_param.to_s}" if options.key?(:anchor) url << Routing::Routes.generate(options, {}) + url << anchor if anchor return url end diff --git a/actionpack/test/controller/url_rewriter_test.rb b/actionpack/test/controller/url_rewriter_test.rb index eee98c49f3..9ca482f79c 100644 --- a/actionpack/test/controller/url_rewriter_test.rb +++ b/actionpack/test/controller/url_rewriter_test.rb @@ -36,6 +36,13 @@ class UrlRewriterTests < Test::Unit::TestCase @rewriter.rewrite(:user => "openid.aol.com/nextangler", :password => "one two?", :controller => 'c', :action => 'a', :id => 'i') ) end + + def test_anchor + assert_equal( + 'http://test.host/c/a/i#anchor', + @rewriter.rewrite(:controller => 'c', :action => 'a', :id => 'i', :anchor => 'anchor') + ) + end def test_overwrite_params @params[:controller] = 'hi' @@ -77,6 +84,12 @@ class UrlWriterTests < Test::Unit::TestCase W.new.url_for :controller => 'c', :action => 'a', :id => 'i' end end + + def test_anchor + assert_equal('/c/a#anchor', + W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :anchor => 'anchor') + ) + end def test_default_host add_host! -- cgit v1.2.3