Search code examples
ruby-on-railsrubyacts-as-taggable-on

Display all tags using acts_as_taggable_on


I'm looking to just dump a list of tags that have been used on my Posts model.

Is there a way to do this with Acts_as_taggable_on?

Thanks


Solution

  • To get a list (with counts) you can do Post.tag_counts_on(:tags) which will return an array of objects that look like this:

    => [#<ActsAsTaggableOn::Tag id: 1, name: "joking", taggings_count: 1>,
        #<ActsAsTaggableOn::Tag id: 2, name: "clowning", taggings_count: 2>,
        #<ActsAsTaggableOn::Tag id: 3, name: "boxing", taggings_count: 1>]
    

    which you can then collect to get the names if you just want that