Get all tags on taggable object - no matter context

若如初见. 提交于 2020-01-07 06:28:12

问题


I use acts-as-taggable-on on a collection of photos. I have a general :tags context and an :objectives context that users use for stuff that is in the photo. In the UI I add both tag contexts into the same box. It would be nice if I could get all tags and objectives on one photo in one command, like:

photo.gimme_all_tags_no_matter_context #would give me combined list of general tags and objectives.

Currently I do this:

tags = "#{photo.tags.map{|c| c.name}.join(",")},#{photo.objectives.map{|c| c.name}.join(",")}"

Is there a way to do that?


回答1:


You table with all tags is

ActsAsTaggableOn::Tagging

To get all tags you do this

ActsAsTaggableOn::Tag.all


来源:https://stackoverflow.com/questions/37689149/get-all-tags-on-taggable-object-no-matter-context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!