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 7248051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:05:13+00:00 2026-05-28T22:05:13+00:00

consider scenario, User model with name, birth_date fields (here birth_date is optional) inside view

  • 0

consider scenario,

User model with name, birth_date fields (here birth_date is optional)

inside view form birth_date is assigned as ’31/31/1985′ which is invalid

ideally user object should be invalid and raise and error on birth_date field but thats not happening and user object gets saved with birth_date as blank which is completely misleading.

After debugging found that while assigning attributes birth_date value it gets assigned as blank and as birth_date is optional object gets saved.

u = User.new
# invalid date assignment
u.birth_date = '31/31/2011'
u.birth_date #=> nil
# valid date assignment
u.birth_date = '1/1/2011'
u.birth_date #=> Sat, 01 Jan 2011

class User < ActiveRecord::Base
  def initialize(args={})
    logger.info args[:birth_date] #invalid value comes upto here but vanishes afterwords
    super
  end
end

I am not saying its incorrect, but it should not misleading from user point of view.
bcz after entering invalid birth_date user will assume he entered correct birth_date but actually his birth_date is not saved at all.

Any clue how to get around this issue ??

  • 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-28T22:05:14+00:00Added an answer on May 28, 2026 at 10:05 pm

    I don’t know whether the allow_blank and allow_nil options work with custom validations, but it’s easy to write it yourself.

    validate :valid_birth_date
    
    private
      def valid_birth_date
        errors.add(:birth_date, "is invalid.") unless birth_date.blank? || valid_date?(birth_date)
      end
    
      def valid_date?(date)
        begin
          !!Date.parse(date)
        rescue
          false
        end
      end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider following scenario: I have RESTful URL /articles that returns list of articles user
Consider the scenario I have values assigned like these Amazon -1 Walmart -2 Target
Consider this scenario; suppose I have WPF window which have four objects bonded to
Consider this scenario in which an executable A.bin uses libY.so and libZ.so. A.c, Y.c
Before I ask my question, please consider this scenario: a user on my website
The title should be pretty clear, but consider this scenario: User bobbyflay registers an
Here's a scenario: I have a java front end (RCP/SWT) app which currently has
Consider these two scenarios: a user presses a button in a view (e.g. Fulfill
Take this scenario for an example: User types http://example.com/index.html into my form Form is
Consider the following scenario: You have an account model You have an external service

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.