views:

80

answers:

1

How to return the number of Posts Tagged with "example" using acts_as_taggable under ROR

currently I am implementing this by declare

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

I wonder if there is any other better solutions out there, thank you in advance!

A: 

You could try using a named scope in the model, then calling count on it, e.g.

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

then:

Questions.tagged_with("example").count

Or something to that effect. find_options_for_find_tagged_with is defined in acts_as_taggable.

Kenny