I’m using Clearance for authentication in my Rails application. The Clearance::User mixin adds a couple of validations to my User model, but there’s one of these that I would like to remove or override. What is the best way of doing this?
The validation in question is
validates_uniqueness_of :email, :case_sensitive => false
which in itself isn’t bad, but I would need to add :scope => :account_id. The problem is that if I add this to my User model
validates_uniqueness_of :email, :scope => :account_id
I get both validations, and the one Clearance adds is more restrictive than mine, so mine has no effect. I need to make sure that only mine runs. How do I do this?
I ended up “solving” the problem with the following hack:
:emailattribute of type:takenSounds reasonable until you read the code and discover how I remove an error.
ActiveRecord::Errorshas no methods to remove errors once added, so I have to grab hold of it’s internals and do it myself. Super duper mega ugly.This is the code:
If anyone knows of a better way, I would be very grateful.