开发者

has_many :through and acts-as-taggable-on

开发者 https://www.devze.com 2023-01-21 06:00 出处:网络
How can I get all the tags for a model\'s associ开发者_运维问答ated models using 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
0

精彩评论

暂无评论...
验证码 换一张
取 消