mbleigh / acts-as-taggable-on

A tagging plugin for Rails applications that allows for custom tagging along dynamic contexts.
http://mbleigh.lighthouseapp.com/projects/10116-acts-as-taggable-on
MIT License
4.98k stars 1.19k forks source link

NoMethodError: undefined method `tagged_with' for … although other methods work fine #863

Closed jasonfb closed 3 years ago

jasonfb commented 7 years ago

We are using acts-as-taggable-on (version 3.5.0 with Rails 4.1)

strangely, tag_list.add and tag_list.remove work fine, but when I call tagged_with on the same object, I get NoMethodError

[8] pry(main)> u.tagged_with("xyz")
NoMethodError: undefined method `tagged_with' for #<Spree::User:0x007ff5632caed8>
from /Users/jason/.rvm/gems/ruby-2.1.5/gems/activemodel-4.1.14.2/lib/active_model/attribute_methods.rb:435:in `method_missing'

my inelegant work-around, which works but is ugly is:

[9] pry(main)> u.tags.collect(&:name).include?("xyz")
=> true

This is a Spree application, which itself has a bunch of gems interoperating. I mention this in case it is relevant.

Is tagged_with implemented via a method_missing?.

The reason I ask is that I suspect maybe there might be other competing code that has already overloaded method_missing in my app, which is the only explanation I can think of as to why this would be like this

(Incidentally, I find the overuse of method missing to be a really bad pattern, as I often have to deal with conflicting gems trying to overload method_missing)

bf4 commented 7 years ago

would you be able to include more of the stack trace?

jasonfb commented 7 years ago

There isn't really a stacktrace, I can simply reproduce this on the Rails console, and it isn't failing inside of the stack, it's just telling me NoMethodError: undefined method `tagged_with' for… for any User object (which has acts_as_taggable on it), and like I said, other methods from this gem work (like tag_list)

The only other debugging thing I think I might be able to provide is to create a simple Spree application that uses the same (open source) gems we use, then add acts_as_taggable to that to see if the problem comes from some interaction of gems. Of course, if I can reproduce it in a sample (test) app, I can push that up to a GH repo for debugging.

djmaze commented 4 years ago

@jasonfb Same problem here. Realized I had a monkeypatch for ActsAsTaggableOn::Taggable::Core in a rails initializer. That made the original class methods from the Core module disappear. After moving the patch inside a after_initialize block, the missing methods would reappear!