Single-table inheritance and validation problem

Stefan Frede
Thu, 19 Mar 2009 09:37:34 -0000

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


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---