My question is similar to another one about putting data from a text_field into a datetime column. It appears that I need to put the data into the text_field in a particular order or rails wont accept it. Thing is, I can’t always control how a user will input the data. In fact, since I just added a JQuery datepicker the value that the user puts in will almost always be wrong.
I thought I could use Date.parse or Time.parse or DateTime.parse along with a setter method (mentioned in railscast 32but that doesn’t seem to be working for me either. I keep getting an argument out of range error which also seems to be due to the input being in the wrong format.
Does anyone else use the JQuery datepicker to fill in a text field for the date? What magic do you have to add to your model or controller to make it work? Why is this so difficult?
I used timeliness gem to overcome this problem and submit the date in the format I wanted. Along with timeliness I also used validates_timeliness to validate the date and time, that is it is not in future or anything.
To parse a string ‘MM/DD/YYYY’ using timeliness gem you would do: