Here's the code.
Tuesday, March 30, 2010
Adding tags to Mongoid Documents
In our latest project at Martian Interactive we are using Mongoid to support some document-based models instead of a relational approach like ActiveRecord models. As many applications, this one needed a tagging system (nothing magic, we all know there are a lot of gems/plugins out there that works pretty fine with AR) for Mongoid documents, so I ended up writting a really basic and simple tagging system that's working pretty well, since we are using a document-based schema each document has it's own set of embedded tags that are loaded when the document is required allowing us to save some queries, with a relational schema this solution wouldn't be an option due to the redundance it introduces.
Subscribe to:
Post Comments (Atom)
9 comments:
Great Post, this is exactly what I needed. Just in case someone else uses this runs into an error, the tags method is missing the closing tag. Add that and you will be good to go.
ah! yes good catch, thanks!
Newbie question.
Where do I need to put this file and with what name?
@fernando You can save that file under /lib/mongoid_tags.rb and then in your environment.rb(rails 2.3.x) or application.rb(rails 3) you can load the lib.
http://stackoverflow.com/questions/3356742/best-way-to-load-module-class-from-lib-folder-in-rails-3
Thanks a lot ... that's what I was looking for .. a simple tagging function ....
Pc games free
gta 4 free download
nice buddy
__________
New pc games
all games full free
Great job.. saved me a bunch of work..
Updated for rails 3.2 with it's mass assignment protection.
Also the mongoid index method changed a bit:
https://gist.github.com/3313759
Post a Comment