Created
August 15, 2011 09:24
-
-
Save mindscratch/1145952 to your computer and use it in GitHub Desktop.
Mongoid: return 'id' instead of '_id' when serializing documents as JSON
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
module Mongoid | |
module Document | |
def as_json(options={}) | |
attrs = super options | |
attrs["id"] = attrs.delete "_id" if attrs.has_key? "_id" | |
attrs | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In a Rails application I place this file in config/initializers