Forum: Ruby on Rails removing duplicates from HABTM

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C3e347393bfc91e02e52656bbea76140?d=identicon&s=25 magic_hat (Guest)
on 2009-01-10 03: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
    puts tag.name
    for relatedArticle in tag.articles
      puts relatedArticle.title
    end
  end

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