Created
March 10, 2010 06:35
-
-
Save seanmccann/327593 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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