Date Validation for date_select


#1

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,
                                      :start_year=>Spec::START_YEAR,
                                      :end_year=>Time.now.year,
                                      :include_blank=>true,
                                      :order =>[:month, :day, :year]

%>

  </div>

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 && birthdate.day > 29)
errors.add(:birthdate, “Invalida date”)
end

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

Could someone explain this to me.
Thanks in advance.


#2

Im sorry the validate method in the model (Spec which stores
specifications of the registered users)