From 5f67cfeda116f2b932ef72781420aa37e62437ca Mon Sep 17 00:00:00 2001 From: choonkeat Date: Wed, 14 Dec 2011 22:43:42 +0800 Subject: Fix url_for options[:subdomain] to allow objects as values * e.g. blog_url(subdomain: current_user) instead of blog_url(subdomain: current_user.to_param) --- actionpack/lib/action_dispatch/http/url.rb | 2 +- actionpack/test/controller/url_for_test.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/http/url.rb b/actionpack/lib/action_dispatch/http/url.rb index 129a8b1031..64459836b5 100644 --- a/actionpack/lib/action_dispatch/http/url.rb +++ b/actionpack/lib/action_dispatch/http/url.rb @@ -70,7 +70,7 @@ module ActionDispatch host = "" unless options[:subdomain] == false - host << (options[:subdomain] || extract_subdomain(options[:host], tld_length)) + host << (options[:subdomain] || extract_subdomain(options[:host], tld_length)).to_param host << "." end host << (options[:domain] || extract_domain(options[:host], tld_length)) diff --git a/actionpack/test/controller/url_for_test.rb b/actionpack/test/controller/url_for_test.rb index dc07e07cb9..288efbf7c3 100644 --- a/actionpack/test/controller/url_for_test.rb +++ b/actionpack/test/controller/url_for_test.rb @@ -71,6 +71,14 @@ module AbstractController ) end + def test_subdomain_may_be_object + model = mock(:to_param => 'api') + add_host! + assert_equal('http://api.basecamphq.com/c/a/i', + W.new.url_for(:subdomain => model, :controller => 'c', :action => 'a', :id => 'i') + ) + end + def test_subdomain_may_be_removed add_host! assert_equal('http://basecamphq.com/c/a/i', -- cgit v1.2.3