Forum: Ruby on Rails Single-table inheritance and validation problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Stefan Frede (Guest)
on 2009-03-19 11:38
(Received via mailing list)
Hi!

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:
http://pastie.org/pastes/419606

So my question is how can I compare the email input to throw an error
if they are the same.

Thanks in advance.

Regards,
Stefan
This topic is locked and can not be replied to.