Skip to content

Instantly share code, notes, and snippets.

@fortuity
Created September 12, 2010 20:37
Show Gist options
  • Save fortuity/576430 to your computer and use it in GitHub Desktop.
Save fortuity/576430 to your computer and use it in GitHub Desktop.
Rails 3 Routing Matching Subdomain and Path
Stuffed::Application.routes.draw do
# This config.routes.rb file replaces the one offered in
# http://github.com/fortuity/rails3-subdomain-devise
# and allows a URL such as
# http://foo.lvh.me:3000/foo
# to be routed to
# http://foo.lvh.me:3000/
# while a URL such as
# http://foo.lvh.me:3000/bar
# throws an error.
class PathMatchesSubdomain
def self.matches?(request)
request.subdomain.include?(request.fullpath.reverse.chop.reverse)
end
end
devise_for :users
resources :users, :only => [:index, :show] do
resources :subdomains, :shallow => true
end
constraints PathMatchesSubdomain do
match '/*keyword' => 'sites#show'
end
match '/' => 'home#index', :constraints => { :subdomain => 'www' }
match '/' => 'sites#show', :constraints => { :subdomain => /.+/ }
root :to => "home#index"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment