Locally, on Unicorn, my subdomain setup works fine. I've followed the heroku subdomain docs to the letter, and also the subdomains Railscast. subdomain.lvh.me:3000 points to the right place, and lvh.me:3000 points correctly to the root defined in routes.rb:
root :to => "pages#home"
However, in my new staging deployment on Heroku's Cedar stack, again using Unicorn, whilst subdomain.mydomain.co.uk points to the right place, mydomain.co.uk doesn't. Instead of going to pages#home as per the routes file, it's hitting the books controller, which it's only meant to do if there's a subdomain in the url, as per routes.rb:
constraints(Subdomain) do
match '/' => 'books#show'
end
My DNS settings are as per the Heroku docs, and the host command returns what the docs say it should. Any ideas?
Add the aliased domain to subdomain.rb:
class Subdomain
def self.matches?(request)
request.subdomain.present? && request.subdomain != "www" && request.subdomain != "nameofmydomain"
end
end
来源:https://stackoverflow.com/questions/7151837/heroku-cedar-rails-3-1rc6-subdomain-routing