Collect users who posted items with ActsasTaggable on Tag in rails 3

7 views
Skip to first unread message

Aruna Chinnamuthu

unread,
Feb 22, 2012, 12:48:41 AM2/22/12
to rubyonra...@googlegroups.com
I am using Rails 3 and Acts as taggable on in my application.

I am fetching the articles associated with the tag by

Article.tagged_with("tagname")

and

Blog.tagged_with("tagname")

Now i would like to collect all the users from the above i.e.., people
who are all posted articles and blogs with this tag Please suggest me..

--
Posted via http://www.ruby-forum.com/.

Tim Shaffer

unread,
Feb 22, 2012, 8:11:10 AM2/22/12
to rubyonra...@googlegroups.com
How do your Article and Blog models relate to the User model?

Assuming User has many Articles and Blogs you can simply do this:

user = User.find_by_whatever("something")
user.articles.tagged_with("tagname")
user.blogs.tagged_with("tagname") 
Reply all
Reply to author
Forward
0 new messages