Skip to content

Instantly share code, notes, and snippets.

@Irostovsky
Forked from clemens/Problem
Created October 7, 2011 08:08
Show Gist options
  • Save Irostovsky/1269749 to your computer and use it in GitHub Desktop.
Save Irostovsky/1269749 to your computer and use it in GitHub Desktop.
When the constraints block is active, I get RoutingError: No route matches "/" when going to localhost:3000. If I comment the block out, it works just fine. But I need both:
http://example.com should render PagesController#show with params[:permalink] being 'index'
http://clemensk.example.com should render ProfilesController#show
Hints anyone?
Thanks!
constraints(Subdomain) do
match '/', :to => 'profiles#show', :as => :profile # works!
end
match '/', :to => 'pages#show', :permalink => 'index' # shortcut root :to => 'pages#show' – either doesn't work
# from railscasts.com
class Subdomain
def self.matches?(request)
i = Rails.env.development? ? 0 : 1 # so I can use localhost:3000
request.subdomain(i).present? && request.subdomain(i) != "www"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment