views:

236

answers:

4

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.

A: 

cap deploy:migrations

Thanks, but it didn't help. Also, both production and development are using the identical database, so if it's data-related it should fail on both or work on both.
Tim Sullivan
A: 

I've seen similar problems to this in which the polymorphic type field is not getting correctly filled in, or when there was some existing data prior to the polymorphic type tag getting added. Is person a subclass? does the _type field contain any null values on the polymorphs table?

Cameron Price
Person isn't a subclass, and there's nothing in the tag table. I should have mentioned that I'm using the same database in both instances, so I don't think it's data-related, which is part of what's driving me mad.
Tim Sullivan
A: 

Just stabbing in the dark here, but has_many_polymorphs doesn't natively add tagging functionality to your models. Instead, you use a generator to create a tagging extensions module that goes into lib/tagging_extensions.rb. The module file has helper methods that add tagging functions, built on top of the has_many_polymorphs base functionality.

So, is it possible that you have the plug-in installed, but not the tagging extensions file?

Alderete
Thanks, but we did indeed include the tagging extensions file! It was a weird one, but it's since been resolved.
Tim Sullivan
A: 

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.

Tim Sullivan