Skip to content

Instantly share code, notes, and snippets.

@foca
Created October 10, 2010 23:48
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 foca/619713 to your computer and use it in GitHub Desktop.
Save foca/619713 to your computer and use it in GitHub Desktop.
# :facepalm:
class User < ActiveRecord::Base
validate do |user|
if user.login.blank?
user.errors.add_to_base("User Name can't be blank")
else
user.errors.add_to_base("User Name is too short(Minimum is 3 characters)") if user.login.length<3 and user.login.length !=0
user.errors.add_to_base("User Name is too long(Maximum is 3 characters)") if user.login.length>40
user.errors.add_to_base("User Name has already been taken.") if User.find_by_login(user.login)
end
end
end
@simi
Copy link

simi commented Oct 11, 2010

WTF?

@Inza
Copy link

Inza commented Oct 11, 2010

Fail:-D...somebody is not able to use :validate_ ...syntax... too bad...

@foca
Copy link
Author

foca commented Oct 11, 2010

The worst thing is that two lines above from that there are calls to validates_uniqueness_of and validates_presence_of :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment