Mongoid::Serializer
Configure Mongoid with Serialization support in Rails Controllers.
Will add id
as an available attribute, which can be used as the primary key as is expected by most API clients.
Inspired by the discussion here: http://stackoverflow.com/questions/11571777/ember-data-and-mongodb-how-to-handle-id
Note: Should work for Mongoid 3+
Installation
Add this line to your application's Gemfile:
gem 'mongoid-serializer'
And then execute:
$ bundle
Or install it yourself as:
$ gem install mongoid-serializer
Usage
class UserSerializer < MongoidSerializer
attributes :id, :first_name, :last_name, :quote, :age
end
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request