Forum: Ruby on Rails How to validate a date_select field

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jason V. (Guest)
on 2007-01-08 07:58
(Received via mailing list)
View [actually in a partial]...

<td>
      <%= date_select 'contract_payment', 'credit_card_expiration_date',
      { :order => [:month, :year], :start_year => 2006, :end_year =>
2020,
:use_month_numbers => true,
      :discard_day => true, :include_blank => true } %>
    </td>

Model :

 validates_presence_of :credit_card_expiration_date,
:credit_card_number

This is not right.  The View renders correctly (minus the hard-coded
2006... not sure yet how to replace that].

I want to make the month and year [sub-]fields required.  I also want
them to be greater than today.  The "validates_presence_of" doesn't
handle both the month and year correctly.

I would really appreciate an example.

Thanks,
Jason
Conrad T. (Guest)
on 2007-01-08 12:02
(Received via mailing list)
Hi, you can try using the following:

http://www.railsonwave.com/railsonwave/2006/12/13/...

or

valid_date?

Good luck,

-Conrad
This topic is locked and can not be replied to.