Last active
August 29, 2015 13:57
-
-
Save Schniz/9558489 to your computer and use it in GitHub Desktop.
I've seen it somewhere.. and I've added the 'date_created' thing that you can't access when you're doing it all RESTy.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Adds "id" and "date_created" to the mongoid document. | |
# "id" => "_id" | |
# "date_created" => "_id.generation_time" | |
# YEAH. thats it. | |
module Mongoid | |
module Document | |
def as_json(options={}) | |
attrs = super(options) | |
attrs["id"] = self.persisted? ? self._id : nil | |
attrs["date_created"] = self.persisted? ? self._id.generation_time : nil | |
attrs | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment