Good tagging solution in Rails with MongoID

What are some good tagging solutions in Rails using MongoID?

It seems to be easy to just add a hash or array to the document, but I'm not sure if this is the best approach.

Maybe some gem? Or a simple trick with attached documents?

+6
mongodb ruby-on-rails-3 mongoid tagging
source share
4 answers

Currently, I have used a very simple approach that works very well: just enable the Array field.

 #app/models/image.rb class Image include Mongoid::Document include Mongoid::Timestamps field :message, :type => String field :tags, :type => Array def self.images_for tag Image.any_in(:tags => [tag]) end end #routes.rb match "tag/:tag" => "images#tag" #/app/controller/images_controller.rb class ImagesController < ApplicationController # GET /tag # GET /tag.xml def tag @images = Image.images_for params[:tag] respond_to do |format| format.html { render "index" } format.xml { render :xml => @images } end end end 

This works, but I still have little doubt about the performance of Image.any_in map / reduce. I think that there may be a better solution for this card / reduction, but not yet found.

+3
source share

Try mongoid_taggable gem. He really wants you to look.

+3
source share

The mongoid-tags-arent-hard gem seems more capable (and more actively supported) than the other gems I've seen.

+3
source share

here it is a β€œscalable” solution for scaling / zooming and real-time strategies mongoid_taggable_with_context

+1
source share

All Articles