2009-08-20 23 views
0

使用acts_as_taggable如何返回ROR如何返回與「榜樣」標籤的帖子下ROR

目前我實現這個與「榜樣」標籤的帖子的使用acts_as_taggable數的數量由申報

<%=Questions.find_tagged_with("example", :match_all => true).size%> 

我想知道是否還有其他更好的解決方案,謝謝!

回答

0

您可以嘗試在模型中使用命名範圍,然後調用它,例如,

named_scope :tagged_with, lambda {|tag| find_options_for_find_tagged_with(tag)} 

則:

Questions.tagged_with("example").count 

或者其他類似的效果。 find_options_for_find_tagged_withacts_as_taggable中定義。

相關問題