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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:03:04+00:00 2026-05-23T10:03:04+00:00

Ok I have 3 select boxes for selecting date of birth. I have constants

  • 0

Ok I have 3 select boxes for selecting date of birth.

I have constants setup in my User model to provide months, years etc..

Anyway I can successfully validate these select boxes separately.

What I want to do is combine the :day, :month and :year and store in :birthday and validate the whole date as one so I can return 1 error rather than 3 separate ones.

Also doing this will make it easier to store the validated date in my birthday field in my database.

Part of my form

    <td> <%= f.input :day, :required => false, :label => "Birthday: " , :prompt => "Day", :collection => User::DAYS  %></td>
 <td> <%= f.input :month, :label => false, :prompt => "Month", :collection => User::MONTHS %> </td> 
 <td> <%= f.input :year, :label => false, :prompt => "Year", :collection => User::YEAR_RANGE %> </td> 

Part of User model

MONTHS = [“January”, 1], [“February”,
2], [“March”, 3], [“April”, 4],
[“May”, 5], [“June”, 6], [“July”, 7],
[“August”, 8], [“September”, 9],
[“October”, 10], [“November”, 11],
[“December”, 12] # finish this DAYS =
1..31 # finish this START_YEAR = Time.now.year – 106 END_YEAR =
Time.now.year YEAR_RANGE =
START_YEAR..END_YEAR

class User < ActiveRecord::Base
attr_accessor :day, :month, :year

validates_presence_of :day, :message
=> ‘What day in a month was you born?’
validates_presence_of :month, :message
=> ‘What month was you born?’
validates_presence_of :year, :message
=> ‘What is your year of birth?’

end

  • 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-23T10:03:04+00:00Added an answer on May 23, 2026 at 10:03 am

    I would change the column to datetime (date never seems to work for me).

      t.datetime :birthday
    

    Then use a date_select in your view.

      <div class="field">
        <%= f.label :birthday %><br />
        <%= f.date_select :birthday, :include_blank => true, :start_year => Time.now.year - 70 %>
      </div>
    

    Then in your model validate birthday presence.

      validates_presence_of :birthday
    

    If you need to make sure the birthday is older than a certain age, write a custom validation.

      validate :of_certain_age
    
    private
    
      def of_certain_age
        if self.birthday
          errors.add(:base, 'You need to be at least 18.') if self.birthday > 18.years.ago
        end
      end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two multi-select list boxes; one with months and one with years such
I have a form where a user can add multiple select boxes for multiple
I have two select boxes with dates. See here the jsfiddle: http://jsfiddle.net/egrba/ The people
I have three select boxes state,city and locality with the id's same as name
I have different select boxes. I want to select second one with related id.
I have 3 select boxes and all are having same value (clones) & created
I have three select boxes :- select1 select2 select3 , i am fetching data
I have multiple multi-select boxes with the same class and i want to unselect
I have two identical select boxes (aside from their names, of course), and I
I have 6 different select boxes and a text field which I need to

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.