I have a pretty simple HABTM set of models
class Tag < ActiveRecord::Base
has_and_belongs_to_many :posts
end
class Post < ActiveRecord::Base
Just add a check in your controller before adding the record. If it does, do nothing, if it doesn't, add a new one:
u = current_user
a = @article
if u.articles.exists?(a)
else
u.articles << a
end
More: "4.4.1.14 collection.exists?(...)" http://edgeguides.rubyonrails.org/association_basics.html#scopes-for-has-and-belongs-to-many