# Acts\_as\_taggable Produces Bad SQL - Find Fails

**URL:** <https://www.ruby-forum.com/t/acts-as-taggable-produces-bad-sql-find-fails/65158>\
**Category:** Rails\
**Created:** [February 9, 2006, 11:56pm UTC](https://www.ruby-forum.com/t/acts-as-taggable-produces-bad-sql-find-fails/65158 "2006-02-09T23:56:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![HHHHHH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/50afbb/32.png) [@HHHHHH](https://www.ruby-forum.com/u/HHHHHH)\
**Post date:** [February 9, 2006, 11:56pm UTC](https://www.ruby-forum.com/t/acts-as-taggable-produces-bad-sql-find-fails/65158/1 "2006-02-09T23:56:35Z")

</div>

I am using acts\_as\_taggable in my application and on the tagging side of  
things, no problem at all. Running edge Rails and PostgreSQL 8.1.

I am then trying to find all my AR objects with a certain tag. The tag  
is:  
lasvegas and I know that there are at least 3 records with that tag.

So, I’m doing this:

@lists = List.find\_tagged\_with :any =\> @search\_string, :separator =\> ‘+’

The problem is that the SQL generated looks like this:

SELECT lists.\* FROM lists, tags, taggings WHERE lists.id =  
taggings.taggable\_id AND taggings.taggable\_type = ‘List’ AND  
taggings.tag\_id  
= tags.id AND tags.name IN (‘anylasvegas’, ‘separator+’)

See what’s right after the IN clause? It says ‘anylasvegas’ - why? BTW,  
using ‘lasvegas’ returns the correct results.

I used the :any symbol in the finder per the instructions and all the  
permutations I tried to get rid of it just gave me syntax errors, etc…

So, am I doing something wrong or what?

Thanks,  
HH

---

<div class="post-metadata">

**Author:** ![HHHHHH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/50afbb/32.png) [@HHHHHH](https://www.ruby-forum.com/u/HHHHHH)\
**Post date:** [February 10, 2006, 12:01am UTC](https://www.ruby-forum.com/t/acts-as-taggable-produces-bad-sql-find-fails/65158/2 "2006-02-10T00:01:42Z")

</div>

This patch might help:

[http://rubyforge.org/tracker/index.php?func=detail&aid=2482&group\_id=923&atid=3629](http://rubyforge.org/tracker/index.php?func=detail&aid=2482&group_id=923&atid=3629)

Cheers,

-San

---

<div class="post-metadata">

**Author:** ![HHHHHH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/50afbb/32.png) [@HHHHHH](https://www.ruby-forum.com/u/HHHHHH)\
**Post date:** [February 10, 2006, 1:27am UTC](https://www.ruby-forum.com/t/acts-as-taggable-produces-bad-sql-find-fails/65158/3 "2006-02-10T01:27:56Z")

</div>

Excellent, I’ll give this a go, thanks.

Anyone know the best way to install this patch?

I tried simply commenting out the old method in the plugin and inserting  
this but I get this exception:

undefined method `split\_tag\_names’ for  
ActiveRecord::Acts::Taggable:Module

Indeed, looking at the plug-in I don’t see that method defined  
anywhere…

What gives?

Thanks,  
Hunter

---

<div class="post-metadata">

**Author:** ![HHHHHH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/50afbb/32.png) [@HHHHHH](https://www.ruby-forum.com/u/HHHHHH)\
**Post date:** [February 10, 2006, 10:31pm UTC](https://www.ruby-forum.com/t/acts-as-taggable-produces-bad-sql-find-fails/65158/4 "2006-02-10T22:31:18Z")

</div>

yeah, i’m having problems, too. i get an error with a later function  
in the gem. any help would be appreciated.
