Rails tags for all Photos in an Album

50 Views Asked by At

I have an Album and a Photo model. Photos have tags via Acts As Taggable On.

Is there a nice Rails'y way to get a list of all the tags contained within an Album? Eg, one combined list of tags of all the photos inside one particular Album?

I know I could grab the Album, iterate its Photos and grabs the tags and then dedupe it but just wondering if there is a much nicer, cleaner, more efficient way to achieve this?

Neil

1

There are 1 best solutions below

3
Hubert Jakubiak On
class Album < ApplicationRecord
  has_many :photos
  has_many :tags, through: :photos
end