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

  • SEARCH
  • Home
  • 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 439683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:47:54+00:00 2026-05-12T20:47:54+00:00

I have a User model with the usual attributes such as email and hashed_password

  • 0

I have a User model with the usual attributes such as email and hashed_password etc. I want to write a validation that checks for the presence of an email address but only when

1) there isn’t one stored in the database for this object (i.e. this is a new user signing up)

2) the user is trying to update their email address.

My current validations

  validates_presence_of :email
  validates_presence_of :email_confirmation

  validates_confirmation_of :email

are obviously preventing me from updating any attributes. I thought of using

validates_presence_of :email , :if :email_validation_required?

def email_validation_required?
self.email.blank?
end

But that wont help with scenario 2 as it will return true because the user does have an password email address in the db.

I cant work out how i can limit it to just those 2 scenarios above.

Can anyone help?

  • 1 1 Answer
  • 2 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-12T20:47:54+00:00Added an answer on May 12, 2026 at 8:47 pm

    I think EmFi is on to something. But I don’t think the validates_presence_of :email should be holding you up. The email should always be present – if it is left blank in the form the parameter will not mess with your save of the user. If it is entered in the form, even for update, it should have an email_confirmation along for the ride.

    Give this a try:

    validates_presence_of :email
    validates_presence_of :email_confirmation, :if => :email_changed?
    
    validates_confirmation_of :email
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a User model with the usual information (login, email, name, location, etc).
In my User model, I have the usual suspects of email, first_name, last_name, password,
I have a User model that Devise manages - i.e. all users have email
I have a User model that has a :credits attribute. I want a simple
I have a User model that has many posts. Im trying to render the
I have a user model on which I check to make sure that the
I have a user model that requires the user to change their password every
I have a User model that has the following default_scope: default_scope where(account_id: Account.current_account.id) If
I'm new to MVC. You have been warned... I have User model that can
I have a standard devise user model with the usual fields. This is for

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.