has_many :through and acts-as-taggable-on
How can I get all the tags for a model's associ开发者_运维问答ated models using acts-as-taggable-on
?
I have the following models, and want to build a list of tags that the network's associated offers have:
class Network < ActiveRecord::Base
has_many :offers
end
class Offer < ActiveRecord::Base
acts_as_taggable
belongs_to :network
end
How do you do that?
Try looping over Network.tag_counts.
Try this:
@network.offers.map{|o| o.tags }.flatten.compact
精彩评论