Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4545160
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:46:26+00:00 2026-05-21T15:46:26+00:00

I have a User class, and a Contact where Contact is a subclass of

  • 0

I have a User class, and a Contact where Contact is a subclass of User. Both classes are stored in a users table.

My Contacts may or may not have an email address, while an email address is required for my Users (I have validates_presence_of :email in my User model definition).

My reasoning is that Contacts are entered by users and may later become Users when they claim their profile.

  • First of all, is it ok to define my
    users and contacts the way I did it?
  • Second, how do I skip the
    validate_presence_of email
    validation in my contacts model?

(I’m on rails 2.3.8)

Thanks!

UPDATE:

  • It seems Single Table Inheritance is
    designed to do exactly what I needed

  • the right way to skip validation for
    the presence of email for my Contact
    table is as follow:

validates_presence_of :email, :unless => Proc.new {|user| user.type == "Contact"}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T15:46:27+00:00Added an answer on May 21, 2026 at 3:46 pm

    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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a User class which may or may not have an associated Department.
I have these classes: class User has_one :user_profile accepts_nested_attributes_for :user_profile attr_accessible :email, :password, :password_confirmation,
i have a User class with a field for the e-mail-address and a password.
I have a class holding the list of contacts of my user in an
i have one contact form, when user submit all value will send(email) to admin.But
I want to have a table of users. These users shall have n contacts
I have a User class with reference to a Message class. The message class
I have a class User with one field called birthDate which is a java.sql.Date
I have a Filter Method in my User Class, that takes in a list
I have an entity loaded by Hibernate (via EntityManager ): User u = em.load(User.class,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.