Skip to content

Instantly share code, notes, and snippets.

@seanmccann
Created March 10, 2010 06:35
Show Gist options
  • Save seanmccann/327593 to your computer and use it in GitHub Desktop.
Save seanmccann/327593 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
acts_as_authentic
validates_format_of :username, :with => /\A[\w-]+\Z/
validate :username_is_not_a_route # prevents usernames that are existing routes
protected
def username_is_not_a_route
path = ActionController::Routing::Routes.recognize_path("/#{username}", :method => :get) rescue nil
errors.add(:username, "conflicts with existing path (/#{username})") if path && !path[:username]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment