allow duplicate taggings using acts
Rails newbie here!
I am using acts-as-taggable-on to implement basic tagging, but I want to modify the default behaviour so that each instance of a model (say a post) can be tagged multiple times using the same tag.
@post.tag_list.add("awesome, awesome", parse: true)
would only create one tag and one tagging in the default behavior. I would like it to use the same tag in the database but to create two unique taggings for that post.
Ultimately I would like to be able to count the number of times @post was tagged with "awesome" so I can make a tag frequency count for each post. What would be the best way to do this that wouldn't require rolling my own tag implementation?
I'm trying to add duplicate tags to a user. I want some user x to have multiple "awesome" tags. The default implementation wont let me.
Default implementation:
@instance.tag_list = "awesome, awesome, awesome"
@instance.save
@instance.reload
@instance.tags =>
[#<ActsAsTaggableOn::Tag id: 1, name: "awesome", taggings_count: 1>]
I want taggings_count to return 3 instead, because I want to make 3 separate taggings to "awesome" even though they all refer to the same tag.
This library already counts the tags. just look at attribute taggings_count
of tag record. As from docs:
@user.tag_list = "awesome, slick, hefty"
@user.save
@user.reload
@user.tags
=> [#<ActsAsTaggableOn::Tag id: 1, name: "awesome", taggings_count: 1>,
#<ActsAsTaggableOn::Tag id: 2, name: "slick", taggings_count: 1>,
#<ActsAsTaggableOn::Tag id: 3, name: "hefty", taggings_count: 1>]
Taggings_coungs is the number of taggings applied.
链接地址: http://www.djcxy.com/p/36014.html上一篇: 在rails中标记索引:添加第二个模型并将其作为标记
下一篇: 允许使用行为重复标记