I’ve got a subscription form in which someone can decide to give a
gift to someone else. So you have to enter subscriber and recipient
data in one form.
For my user model I use single-table inheritance. It works fine but
I’ve got a bug in the validation which I’m not able to solve.
For both users, subscriber and recipient, you have to enter an email
address. It is important that the email address is unique so you have
to enter two different email addresses.
In my parent user model I validate the email input with
validates_uniqueness_of :email. This checks if there is an existing
email address in the database already but not if the email input of
both users are the same.
My bug is due to the save order and the validation of uniqueness that
then the second user will not be saved but the system also do not
throw an error.
I hope this is somehow understandable. Here some code that hopefully
shows the problem:
So my question is how can I compare the email input to throw an error
if they are the same.
Thanks in advance.