Search code examples
ruby-on-railshas-many-polymorphs

has_many_polymorphs tagging - works on development machine, not on production!


I'm having a weird problem, where tagging works fine on my development machine, but when I deploy to the production server, I get this error in the log:

ActionView::TemplateError (undefined method `tags' for #<Person:0x98bb9d4>) on line...  

There is an entry in the production.log file that states that has_many_polymorphs is loaded, so it's not like the plugin isn't available on the production machine.

My Google-fu has failed me trying to find the answer, so if anyone knows what could be wrong it would be greatly appreciated!

Edit: I should have mentioned that on both production and development I'm using the same database. I downloaded the production one, and used it on the development machine and it works fine.


Solution

  • I spent some time with a consultant tracking this down, and eventually we discovered that for reasons unknown, the Tagging stuff just wasn't being loaded.

    By adding a single line of code, just three letters, to the end of environment.rb, it was resolved. I commented it so that we'd never forget wtf was going on:

    # Magic begins here.
    # We need to force Rails to load the Tag record, or 
    # has_many_polymorphs doesn't work properly. I don't know
    # if there's a better fix, but this one seems reasonable. :-/
    Tag
    

    That was it. I'm sure there's an elegant and proper solution to this, but this works. Weird.

    I hope this helps someone out there.