Forum: Ruby on Rails date_select and date validation

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.
8b0b8075029e98a11930718b019b07f4?d=identicon&s=25 Cathal O. (coriordan)
on 2006-06-13 12:55
Hi,

I've put together a simple form that contains among other things a
date_select:

<%= date_select(:user, :dob, :order => [:day, :month, :year],
:start_year => 1900, :end_year => Date.today.year) %>

In my controller I have some code to create a user entity from the
parameters posted up from the form, like so:

parameters: {"user"=>{"dob(1i)"=>"2006", "dob(2i)"=>"2",
"dob(3i)"=>"31"}}

@user = User.new(params[:user])

As if by magic Rails will convert dates like 02/31/2006 into 03/03/2006
so at the model level 'user.dob' => '03/03/2006'.

Is there a way to switch off this behaviour? In my opinion, an invalid
date shouldn't result in a valid one being created.

regards,
C.
This topic is locked and can not be replied to.