be_taggable patch


linus 07/14  
Happy_face_w50 Hello!
I have wrote two new methods for be_taggable:

    # add tags
def add_tags(str)
new_tags = self.class.split_tag_names(str)

new_tags_objs = []
new_tags.each{|tag|
new_tags_objs << Tag.find_or_create_by_name_and_model_type(tag, self.class.name)
}
self.tags = (self.tags + new_tags_objs).uniq

update_attribute(:tags_cache, self.tag_names.to_yaml) if respond_to? :tags_cache
end

# remove tags
def remove_tags(str)
new_tags = self.class.split_tag_names(str)

new_tags_objs = []
new_tags.each{|tag|
new_tags_objs << Tag.find_or_create_by_name_and_model_type(tag, self.class.name)
}
self.tags = (self.tags - new_tags_objs).uniq

update_attribute(:tags_cache, self.tag_names.to_yaml) if respond_to? :tags_cache
end

The reason for writing those was appling changes tags to groups of objects, when I either wanted to add or remove some tags :)

Cheers,
Tomasz Bak
 
 
login or sign up to participate.




Money_dollar moneywill