I am using acts_as_taggable to create a tag cloud for my application. I have a model 'Question' which is using the acts_as_taggable plug-in. I basically want to filter the tags for the question model.
I also have a 'Subject' model. So the relation between subjects and questions is that a subject has many questions, and a question belongs to a subject.
So when i call @subject.questions.tag_counts, it works fine. But say I call
@subject.free_questions.tag_counts, where free_questions is a method I've defined, it gives a me an "undefined_method tag_counts for #<Array>. I basically want to find all the tags for a subset of the questions.
Can anybody suggest a workaround?
It may help to implement
free_questionsas anamed_scopeso you can call association methods on it.Something like:
Then you can:
and I suspect this may work as well. (don't have a lot of experience with
acts_as_taggable)When you use a
named_scope(instead of a model method you've defined) you get back a proxy object that looks and acts like anArray, but allows you to chainActiveRecordassociation methods onto it. Any methods that work on@subject.questionsyou should be able to call on@subject.questions.free.