I'm using Devise gem for a RoR project and I got an issue on it. I've a single table inheritance User which should have an email and password, but I also have a customer model which inherit from the User model and this model will never have a password and might or not have an email. That email is only a field for customer's profile information.
def User < ActiveRecord::Base
devise ..., :validatable
end
def Customer < User
def email_required?
false
end
def password_required?
false
end
end
My problem is when I'm creating my first customer with an empty email field, it create a customer with an empty email but for the second customer I got an error:
PG::Error: ERROR: duplicate key value violates unique constraint "index_users_on_email" DETAIL: Key (email)=() already exists.
It tries to create a other customer but with the same empty email. By default Devise sets an uniqueness validation on email and a default value "".
Thanks