I have a simple search form in rails 3 that has two date fields. I'm having a problem getting these dates into my mysql db.
I've tried using the american_date gem, specifying date formats in my initializers, in the config/locales/en.yml file, and directly on the date on the date fields themselves. Currently, I'm setting the rails-approved date format in the view -
<%= f.text_field :depart_date, :value=> Date.today.strftime('%Y-%m-%d') %>
The dateformat in my DB is also YYYY-mm-dd, so things should be going smoothly.
The console tells me that the two date fields are both class = "Date"
I think I've found the disconnect. From the logs -
Started POST "/searches" for 127.0.0.1 at 2013-10-30 17:43:26 -0400
Processing by SearchesController#create as HTML
Parameters: {"utf8"=>"√","search"=>{"depart_date"=>"2013-10-30",
"return_date"=>"2013-11-09"}
←[1m←[35m (0.0ms)←[0m BEGIN
←[1m←[36mSQL (0.0ms)←[0m ←[1mINSERT INTO `searches` (`depart_date`,`return_date`)
VALUES ('2013-30-10','2013-09-11')←[0m
←[1m←[35m (2.0ms)←[0m COMMIT
Note that the month and day values are switched in the insert statement. How can I prevent this from happenening?
<%= f.text_field :depart_date, :value=> Date.today %>Date.today.strftime('%m/%d/%Y'):value=> Date.todayshows the current date as "10/31/2013", but still tries to save it as2013-31-10. I triedDate.today.strftime('%m/%d/%Y'), but it does the same, as well.