Ants
Collection of concerns and helpers for Rails + Mongoid + Character web development
Orderable
Adds ordering functionality to the model. Default order is assending by _position field.
Usage:
include Ants:Orderable
NOTE: If this concern is added to model with already existing documents, value for _position field should be initialized with this command:
ModelClass.all.set(_position: 1000)
Meta
Adds set of page meta fields and creates default methods that should be overriden if necessary:
_meta_title_meta_description_meta_keywords_opengraph_image_url
Usage:
include Ants:Meta
Hideable
When you need to hide some documents from public or often used as draft analogue:
Usage:
include Ants:Hideable
Scopes:
hiddennot_hidden
Helpers:
hide!unhide!hidden?
Slug
Sorted Relations
In Mongoid, the HM & HABTM relations return docs in random order. This workaround provides an ability to retrieve related documents in the same order it was stored.
Usage example:
class Post
include Mongoid::Document
include Ants::SortedRelations
field :title
has_and_belongs_to_many :authors
sorted_relations_for :authors
end
post = Post.new title: 'RESTful actions with Mongosteen'
post. = [ Author.create(name: "Oleksandr Kravets").id,
Author.create(name: "Roman Brazhnyk" ).id,
Author.create(name: "Maxim Melnyk" ).id ]
post..map(&:name)
#=> ['Alexander Kravets', 'Roman Brazhnyk', 'Maxim Melnyk']
Versions
Provides a helper method to get a list of document versions, used by chr + mongosteen:
Usage:
include Ants:Versions
Helpers:
_document_versions