# Problem with acts\_as\_taggable and :uniq option

**URL:** <https://www.ruby-forum.com/t/problem-with-acts-as-taggable-and-uniq-option/171671>\
**Category:** Rails\
**Created:** [July 7, 2009, 1:25pm UTC](https://www.ruby-forum.com/t/problem-with-acts-as-taggable-and-uniq-option/171671 "2009-07-07T13:25:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [July 7, 2009, 1:25pm UTC](https://www.ruby-forum.com/t/problem-with-acts-as-taggable-and-uniq-option/171671/1 "2009-07-07T13:25:45Z")

</div>

I’m using acts\_as\_taggable which provides a polymorphic join table  
(taggings) between a Tag and some other class of object (Resource in  
this case). Tagging has the fields “tag”, “taggable\_id” and  
“taggable\_type”. I’m in rails 2.2.2.

I’m trying to set it up so that the same object can’t be tagged with the  
same tag twice. According to the api, this is as simple as setting  
:uniq =\> true on the has\_many :through association. But, this doesn’t  
work for me. I tried setting it on the main association instead/as  
well, but no combination (of putting uniq on either or both  
associations) seems to work.

#in Resource  
has\_many :taggings, :foreign\_key =\> “taggable\_id”, :dependent =\>  
:destroy, :uniq =\> true  
has\_many :tags, :through =\> :taggings, :uniq =\> true

I can get the join record to fail validation if it’s a duplicate of an  
existing record, like so:

#in Tagging  
validates\_uniqueness\_of :tag\_id, :scope =\> [:taggable\_id,  
:taggable\_type]

But, i’d like to get the uniq option working so that it just silently  
doesn’t add the duplicates rather than raising validation errors.

Can anyone help?  
thanks, max
