0
votes

The date field when save to mongodb is in the format of:

{ "_id" : ObjectId("4f03283e1d4ee82215000002"), "name" : "nano3", "category_id" : ObjectId("4f022b411d4ee8105700001c"), "price" : 20, "production_date(3i)" : "1", "production_date(2i)" : "1", "production_date(1i)" : "2011", "description" : "a music player with video play function" }

when I try to get the date using @product.production_date from my model it failed. I am using Mongoid mapper

1
I believe that horrible format comes from dropboxes generated by date_select helper. If that's the case and you don't mind changing the way you store date in DB you'd better create Date object from params that come in request and then store it into DB. In that case there'll be no problems with storing and retrieving it back from DB. If you share more code you can get more help regarding these changes. - KL-7

1 Answers

1
votes

It fails because you don't have any fields named "production_date".

What you do have is fields named "production_date(3i)", "production_date(2i)", and "production_date(1i)".

You should be saving instances of the time class which can be properly serialized by the ruby driver.

Time.now or Time.utc(2011,1,1) will probably do what you want.