Wednesday, 21 August 2013

Why is rails telling me User exists?

Why is rails telling me User exists?

I'm going through the well known Rails tutorial and I'm hitting something
I don't understand.
If I try going against my validation routines by entering a user whose
name or password is too short, when I try to do user.save in the rails
console, the error I get is User Exists.
Why am I getting that particular error, which is of course not the right
one? I do have a uniqueness validation set up, but that's not the one that
should be triggered here.
class User < ActiveRecord::Base
before_save { self.email = email.downcase }
validates :name, presence: true, length: { maximum: 50, minimum: 8 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
has_secure_password
validates :password, length: { minimum: 8 }
end

No comments:

Post a Comment