Forum: Ruby on Rails Date Validation for date_select

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
5b1eca209b1b486ff1732ffb7c745f0e?d=identicon&s=25 Siddharth Ravichandran (sid_on_rails)
on 2009-03-14 02:11
I am new to Rails and I am building this website based on the tutorials
from a book called Railspace. My problem is I have a form page which
accepts the date for
a birthdate field

      <div class="form_row">
        <label for="birthdate"> Birthdate </label>
        <%= date_select :spec, :birthdate,
                                          :order =>[:month, :day, :year]


It works fine when I enter correct dates but when I try entering
something like Feb 31 2009 it gives me the following error.

       1 error(s) on assignment of multiparameter attributes

My parameter variable shows that its being passed as 3 seperate values
(that is my understanding please correct me if I am wrong)

{"commit"=>"Update", "spec"=>{"city"=>"Atlanta", "occupation"=>"Software
programmer", "zip_code"=>"21312", "birthdate(1i)"=>"1907",
"gender"=>"Male", "birthdate(2i)"=>"2", "birthdate(3i)"=>"31",
"first_name"=>"Dilbert", "last_name"=>"Dilbert", "state"=>"Georgia"}}

I cannot seem to validate this using the validate method on the
controller as I am unable to fetch the values of the parameters.
Ive tried using something like

def validate
 if (birthdate.month==2 && > 29)
       errors.add(:birthdate, "Invalida date")

but its seems to completely bypass this. It works correctly when i
simply type
 if(birthdate.month==2 )
but I dont seem to understand why I cannot validate it.

Could someone explain this to me.
Thanks in advance.
5b1eca209b1b486ff1732ffb7c745f0e?d=identicon&s=25 Siddharth Ravichandran (sid_on_rails)
on 2009-03-14 02:13
Im sorry the validate method in the model (Spec which stores
specifications of the registered users)
This topic is locked and can not be replied to.