An easy way to make mongoid documentation order-able.
This class is extracted from benedikt’s great gem github.com/benedikt/mongoid-tree with some modifications. Thanks to benedikt!
-
mongoid (>= 2.0.0.beta.20)
To install mongoid_order, simply add it to your Gemfile:
gem 'mongoid_order'
In order to get the latest development version of mongoid_order:
gem 'mongoid_order', :git => 'https://github.com/arkxu/mongoid_order.git'
And then:
bundle install
Add the include Mongoid::Orderable
in the model:
class Node include Mongoid::Document include Mongoid::Orderable end
This will add a position
field to your document and provide additional utility methods:
node.move_up node.move_down node.move_to_top node.move_to_bottom node.move_above(other) node.move_below(other) node.at_top? node.at_bottom?
See github.com/arkxu/mongoid_order/issues
See github.com/arkxu/mongoid_order and feel free to fork it!
See a list of all contributors at github.com/arkxu/mongoid_order/contributors. Thanks a lot everyone!
Copyright © 2011 Ark Xu. See LICENSE for details.