Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 266
Harshal_m_joshi Avatar asked Dec 27 '22 03:12

Harshal_m_joshi


1 Answers

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  
like image 197
DanS Avatar answered Jan 14 '23 12:01

DanS