Created
September 12, 2010 20:37
-
-
Save fortuity/576430 to your computer and use it in GitHub Desktop.
Rails 3 Routing Matching Subdomain and Path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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