Skip to content

Instantly share code, notes, and snippets.

@benschwarz
Created November 21, 2008 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benschwarz/27292 to your computer and use it in GitHub Desktop.
Save benschwarz/27292 to your computer and use it in GitHub Desktop.
# Extend the Request class to give
# a useful method to be able to route
# to subdomains
module Merb
class Request
def subdomain
return nil if subdomains.first == "www"
return subdomains.first
end
end
end
Merb::Router.prepare do |r|
match(:subdomain => /(.+)/).to(:username => ":subdomain[1]") do
# Everything within this block is sent :username => "mysubdomain"
resources :posts
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment