Forum: Ruby on Rails removing duplicates from HABTM

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
magic_hat (Guest)
on 2009-01-10 04:41
(Received via mailing list)
Hey, folks.

I have articles, which have and belong to many tags. For a given
article, I need to produce a list of tags and associated articles, but
make sure that an associated article doesn't appear under more than
one tag. Also need to limit the list to 3 articles for each tag, and
make sure the given article doesn't appear in the list.

I've started it like so, but it's ugly and still contains duplicate
articles, and I'm drifting into array/hash insanity.

  for tag in article.tags
    for relatedArticle in tag.articles
      puts relatedArticle.title

Any suggestions appreciated!
This topic is locked and can not be replied to.