EDIT: I found a much simpler way: http://www.arctickiwi.com/blog/7-host-and-domain-based-routing-in-ruby-on-rails
Not quite the answer, but this is the best I can give. Perhaps this will help too.
Ideally, this blog post from transfs.com and subdomain-fu should do the trick. However, I am trying to implement it, and they do not seem to play well together.
Basically, if I don't turn on the intiializer, the subdomain route works fine. If I turn on the initializer, the subdomain route breaks (everything gets caught by map.root). I have a feeling that he is building a condition string in the initializer. If you can understand how it breaks, then you will have a working application.
My initializer:
module ActionController module Routing class RouteSet def extract_request_environment(request) env = { :method => request.method } env[:domain] = request.domain if request.domain env[:host] = request.host if request.host
env end end class Route alias_method :old_recognition_conditions, :recognition_conditions def recognition_conditions result = old_recognition_conditions [:host, :domain].each do |key| if conditions[key] operator = "===" if conditions[key].is_a?(Regexp) operator = "=~" end result << "conditions[:#{key.to_s}] #{operator} env[:#{key.to_s}]" end end result end end# end class Route end end
My routes (for development only). You will see my local development domain, stiltify.dev. Sorry, I tried to make it look good here, but I could not make the code block look beautiful. Instead, I put on a paste: http://pastie.org/940619 .
The comment section in the screencast of Ryan Bates was very useful and made me figure out the subdomain => false and other errors they entered. However, the problem persists!
Ramon Tayag Apr 30 '10 at 17:50 2010-04-30 17:50
source share