I know what my problem is I just don't know where to go for a solution. I am using best_in_place with a date. I have the date picker popping up and I can select a date. My problem, I think, is in my controller. If I pick a date with the same month and day like December 12th or February 2nd it works. However if I pick December 11th or February 3rd the date is getting saved as November 12th or March 2nd.
My controller code is
def update
respond_to do |format|
if @order.update(order_params)
puts "Updating! #{order_params}"
format.html { redirect_to @order, notice: 'Order was successfully updated.' }
format.json { respond_with_bip(@order) }
else
format.html { render :edit }
format.json { render json: @order.errors, status: :unprocessable_entity }
end
end
end
If I pick December 19th my "puts" outputs {"ordered_on"=>"12/19/2014"} and it is not saved in the database. I'm using postgresql as the back end and I'm guessing the problem is the database is expecting a string dd/mm/yy instead of mm/dd/yy which is why February 3rd is getting saved as March 2nd.
What is the best place to fix this?
Rails will only accept dates in a certain format. In your javascript you have to set a default format for datepicker fields.
$.datepicker.setDefaults({
dateFormat: 'yy-mm-dd'
});