When I submit my form I can see the date being sent to in the post. However, It doesn't save the date. If I do a date check it says it is not in the proper format. Here is my date picker function, it displays fine:
$j(function(){
$j("#mile_date").datepicker();
});
the $j is because I am using prototype as well so all jquery calls are using the the noconflict variable.
Here is the post:
Parameters: {"utf8"=>"Γ£ô", "authenticity_token"=>"Fj4HW/B4EOan/vcPZLJ75TvWkRH4ZKSFsPLlQLSD0cI=", "mile"=>{"odometer"=>"", "trip"=>"428.2
", "gallons"=>"24.959", "note"=>"", "temperature"=>"", "date"=>"06/22/2011"}, "commit"=>"Create Mile"}
So it sends the date fine but rails doesn't seem to like the format. It inserts a null value into the database. If I submit it with the default datefield with the drop downs it sends this and saves fine:
Parameters: {"utf8"=>"Γ£ô", "authenticity_token"=>"Fj4HW/B4EOan/vcPZLJ75TvWkRH4ZKSFsPLlQLSD0cI=", "mile"=>{"odometer"=>"", "trip"=>"428.2
", "gallons"=>"24.959", "mpg"=>"17.156136063144", "note"=>"", "temperature"=>"", "date(1i)"=>"2011", "date(2i)"=>"6", "date(3i)"=>"22"}, "c
ommit"=>"Create Mile"}
In the insert statement it inserts the date as:'2011-06-22'
Does Rails expect the date in 3 variables to construct the date format correctly? How can I get the datepicker to send the correct date format?
Thank you in advance,
I ran into the same issue. One solution is to simply change the format that the datepicker uses:
// in your javascript...
$j(function(){
$j("#mile_date").datepicker({
dateFormat: "yy-mm-dd"
});
});
Rails seems to be able to handle the yy-mm-dd format - I'm using that and am having no issues saving the date to the database. The only issue here is that some might find the yy-mm-dd format a little less good looking than mm/dd/yyyy...