tags:

views:

78

answers:

2

Hi guys i am having a problem of validating the date if it's wrong.e.g if i search for a record in the database for 31 february it only show me the error in the server, and it doesn't display anything..i dont have a clue what to do help please...

my code for storing my hash date is @start = "#{params[:start][:day]}-#{params[:start][:month]}-#{params[:start][:year]}" and for passing is`@start_date = Date.parse(@start)

` and it returns immediately after detecting that the date passed is wrong and it doesnt give me a chance to validate it.

+3  A: 

Date.parse raises an ArgumentError if you pass an invalid date such as Feb. 31. You can rescue the error if you want to respond to it instead of letting it stop execution. It might be preferable to do a sanity check before you try parsing the date in the first place, though.

Chuck
Thanks dude that really helped..i used the rescue one to solve the problem, keep it up
Donald
A: 

There's not very good date validation built into rails. You might want to try "validates_date_time" by Jonathan Viney.

found here: http://svn.viney.net.nz/things/rails/plugins/validates_date_time/

rledley