Skip to content

Instantly share code, notes, and snippets.

@joshuamiller
Created March 7, 2011 23:14
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 joshuamiller/859475 to your computer and use it in GitHub Desktop.
Save joshuamiller/859475 to your computer and use it in GitHub Desktop.
class UsernameConstraint
def matches?(request)
if /^\/(?<username>[a-zA-Z0-9-]+)/ =~ request.path
User.exists?(:conditions => {:username => username})
end
end
end
#...
constraints UsernameConstraint.new do
scope '/:username' do
get '/' => 'users#show', :as => 'user_home'
resources :posts, :as => 'user_posts'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment