has_many_polymorphs 标记 - 适用于开发机器,不适用于生产!

发布于 2024-07-08 23:51:28 字数 397 浏览 6 评论 0原文

我遇到了一个奇怪的问题,标记在我的开发计算机上工作正常,但是当我部署到生产服务器时,我在日志中收到此错误:

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

Production.log 中有一个条目文件指出已加载 has_many_polymorphs ,因此该插件在生产计算机上并不可用。

我的 Google-fu 未能让我找到答案,所以如果有人知道可能出了什么问题,我将不胜感激!

编辑:我应该提到,在生产和开发中我都使用相同的数据库。 我下载了生产版,并在开发机器上使用它,效果很好。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

奈何桥上唱咆哮 2024-07-15 23:51:28

部署上限:迁移

cap deploy:migrations

素食主义者 2024-07-15 23:51:28

我见过与此类似的问题,其中多态类型字段未正确填写,或者在添加多态类型标记之前存在一些现有数据。 人是一个子类吗? 多态表上的 _type 字段是否包含任何空值?

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?

疧_╮線 2024-07-15 23:51:28

只是在这里摸索,但 has_many_polymorphs 本身并不向模型添加标记功能。 相反,您使用生成器创建一个标记扩展模块,该模块进入 lib/tagging_extensions.rb。 该模块文件具有添加标记函数的辅助方法,这些函数构建在 has_many_polymorphs 基本功能之上。

那么,是否有可能您安装了插件,但没有安装标记扩展文件?

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?

不醒的梦 2024-07-15 23:51:28

我花了一些时间与顾问一起追踪这个问题,最终我们发现,由于未知的原因,标签内容没有被加载。

通过在environment.rb 末尾添加一行代码(仅三个字母),问题就得到了解决。 我评论了它,这样我们就永远不会忘记正在发生的事情:

# 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

就是这样。 我确信有一个优雅且正确的解决方案,但这是可行的。 诡异的。

我希望这对那里的人有帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文