"YOU AND THE ART OF ONLINE DATING" is the only product on the market that will take you step-by-step through the process of online dating, provide you with the resources to help ensure success. Get it now!
It sounds like you should abstract out User and Contacts into two tables instead of trying to consolidate them into one. Although contacts can become users, that doesn't mean that they will (I think? ).
It sounds like you should abstract out User and Contacts into two tables instead of trying to consolidate them into one. Although contacts can become users, that doesn't mean that they will (I think? ).
This would also solve your validate_presence_of :email question, as the contact table/model wouldn't even have the field. It would also alleviate potential performance concerns later on, I believe. You wouldn't want to have a ton of contacts to sort through to find a registered user.
If you're dead-set on doing it in one table though, I believe you can do something like the following: validates_presence_of :email, :unless => Proc. New {|user| user. Type == "Contact"} This is assuming that you have a user_type column, but you could replace that depending on how you're determining whether a User is a Contact.
Update: This is how you'd correctly validate the models: Remove the validates_presence_of from the model and place it inside of this block: with_options :unless => :user_type == "contact" do |user| user. Validates_presence_of :email end.
I currently have a "user_type" field in my users table that says whether the row is for a user or a contact. Having both in the same table makes it easier for me to transform a contact into a user when they claim their profile. And all the fields are similar, only the validation on email is different.
That's why I'd like to use the same table. Any clue how I could bypass the validation for the email field (alternatively, I can do Contact. Save(false), but it skips all validations, not just the email.
– alex Apr 24 at 21:37 I understand that and it's not necessarily a bad way to do things. To my understanding, users could potentially have hundreds of contacts that wouldn't necessarily be registered users. If your site grew to 100,000 users, think of the performance implications of consolidating that into one table.
Although it's not a problem currently, it would be more of a hassle to switch it if that ever occurs then just doing the design change now. You're essentially trading more database calls for not having a potentially huge table. – Chuck Apr 24 at 21:41 Also, look at my updated answer.
The validates_presence_of :email unless... bit should work, if memory serves me correctly. – Chuck Apr 24 at 21:42 Thanks for pointing me to the right direction. I couldn't get it to work with with_options but it works fine with unless (the exact syntax is: validates_presence_of :email, :unless => Proc.
New {|user| user. Type == "Contact"}. Also, I renamed user_type to type so I can use a Single Table Inheritance which I believe is designed to do exactly what I want... I'm keeping it this way for now... maybe will add a Contact table later... don't have time to make the changes now.
– alex Apr 24 at 23:40 No problem man. I hadn't tried with_options, it was just something I found on the internet that seemed pertinent. I'm glad you got it working though, I'll update the answer to reflect your fix.
– Chuck Apr 247 at 0:48.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.