0
使用acts_as_taggable如何返回ROR如何返回與「榜樣」標籤的帖子下ROR
下目前我實現這個與「榜樣」標籤的帖子的使用acts_as_taggable數的數量由申報
<%=Questions.find_tagged_with("example", :match_all => true).size%>
我想知道是否還有其他更好的解決方案,謝謝!
使用acts_as_taggable如何返回ROR如何返回與「榜樣」標籤的帖子下ROR
下目前我實現這個與「榜樣」標籤的帖子的使用acts_as_taggable數的數量由申報
<%=Questions.find_tagged_with("example", :match_all => true).size%>
我想知道是否還有其他更好的解決方案,謝謝!
您可以嘗試在模型中使用命名範圍,然後調用它,例如,
named_scope :tagged_with, lambda {|tag| find_options_for_find_tagged_with(tag)}
則:
Questions.tagged_with("example").count
或者其他類似的效果。 find_options_for_find_tagged_with
在acts_as_taggable
中定義。