我正在使用Rails 4.1.5 & Mongoid 4.0。 我的API返回蒙戈ID的哈希如何在json响应中返回mongo id作为字符串
{
_id: {
$oid: "541e79bc616b684e75000000"
}
created_at: "2014-09-21T07:09:48.599Z"
}
我想是这样的
{
id: "541e79bc616b684e75000000"
created_at: "2014-09-21T07:09:48.599Z"
}
我已经检查this question了,但我不知道在哪个文件,我需要把这个提到的变化回答
您只需创建一个名为mongoid.rb文件,在lib文件夹中。 – Santhosh 2014-09-22 06:29:52
我在libs文件夹中创建了两个文件moped.rb&mongoid.rb,但问题不是用[this answer]解决(http://stackoverflow.com/questions/23505247/have-to-json-return-a-mongoid -as-a-string) – Akhil 2014-09-22 06:46:52
您是否重新启动服务器? – Santhosh 2014-09-22 07:17:57