I have a pretty simple HABTM set of models
class Tag < ActiveRecord::Base
has_and_belongs_to_many :posts
end
class Post < ActiveRecord::Base
In addition the suggestions above:
:uniq
to the has_and_belongs_to_many
association I would do an explicit check to determine if the relationship already exists. For instance:
post = Post.find(1)
tag = Tag.find(2)
post.tags << tag unless post.tags.include?(tag)