acts_as_taggable_on :weirdness
I’ve spent a large part of my day tracking down a very weird behavior in the acts_as_taggable_on plugin. I am using it to tag articles with multiple categories. In general, it’s awesome.
The weirdness comes in with the specific tags that I am using. For example, one article might be tagged “DHCP” as it refers to that protocol. However, as soon as I created a “DHCPv6” tag, my Article.tagged_with("DHCP") stopped working.
I tracked it down to Line 161 which builds a list of tags like the one you are looking for, and if it’s a different length than your tag list, it returns a query condition that will always fail, thus preventing any results. Why does it do that?
The solution, was to specify :all => true in my Article.tagged_with call.
irb _
How have I missed this until now? When in Ruby’s irb, you can use ‘_’ to reference the previous result of anything.
>> 10 + 3
=> 13
>> _ + 2
=> 15
>> _ / 3
=> 5
>>
Very useful.
A beautifully done screencast - or katacast as they are calling them - featuring some TDD with Ruby. It is a fairly simple example, but executed perfectly. Having the Rachmaninov Piano Concerto #3 as the soundtrack really adds to the drama.