Harshal_m_joshi
Harshal_m_joshi

Reputation: 1499

Want to use "acts-as-taggable-on" for mongoid

I want to use "acts-as-taggable-on" gem for my rails app. (rails 3.0.10 and ruby 1.9.2p0)

but I am using mongoid.

as "acts-as-taggable-on" works on AR, is there any way to use this for mongo.

or is there any other gem available for tagging which can be use with mongo.

Upvotes: 4

Views: 1704

Answers (1)

DanS
DanS

Reputation: 18463

Here are a couple of existing solutions for mongoid:

https://github.com/wilkerlucio/mongoid_taggable

http://abhishiv.tumblr.com/post/3623498128/introducing-acts-as-taggable-for-mongoid

However, it's easy enough to write your own tagging functionality using a has_and_belongs_to_many association and a couple of methods in your model:

has_and_belongs_to_many :tags
attr_accessor :tag_list

def tag_list=value
  value.split(',').each do |tag|
    self.tags.build(:name => tag).save
  end
end

def tag_list
  self.tags.join(',')
end  

Upvotes: 10

Related Questions