I want to interrupt the default registration action in my rails application, changing email validation. All I need is to have email field unique ONLY if that user is already registered AND has role 'X'
.
I've tried the following but my application returns "Email has already been taken"
message:
validation:
validates_uniqueness_of :email, {allow_blank: true, if: :already_exists_as_x?}
def already_exists_as_x?
User.where(email: self.email, role: :X).exists?
end
(I will be glad for any help)