I've followed the tutorial available at http://railscasts.com/episodes/221-subdomains-in-rails-3.
It allows you to pass a subdomain option to your routes by overriding the url_for method in a helper file. I've helper method looks like this:
module UrlHelper
def with_subdomain(subdomain)
subdomain = (subdomain || "")
subdomain += "." unless subdomain.empty?
[subdomain, request.domain, request.port_string].join
end
def url_for(options = nil)
if options.kind_of?(Hash) && options.has_key?(:subdomain)
options[:host] = with_subdomain(options.delete(:subdomain))
end
super
end
end
so:
sites_homepage_url(:subdomain => "cats")
produces the url:
"http://cats.example.com/sites/1/homepage"
This works fine in development. In my cucumber tests, however, using:
sites_homepage_url(:subdomain => "cats")
produces:
"http://www.example.com/sites/1/homepage?subdomain=cats"
which indicates the functionality I added to url_for in the helper isn't working. Anyone got any ideas?
Edit: Formatting and added the code for the UrlHelper.