Ruby on Rails 应用程序未在生产模式下启动

发布于 2024-08-31 22:45:43 字数 1955 浏览 1 评论 0原文

在开发模式下一切正常,但是当我尝试在生产模式(RAILS_ENV=生产脚本/服务器)启动我的应用程序时,我收到以下错误:

/opt/ruby1.8/lib/ruby/gems/1.8/gems/searchlogic-2.4.19/lib/searchlogic/named_scopes/conditions.rb:81:in `method_missing': protected method `scope' called for #<Class:0x7f41de524410> (NoMethodError)                                                                                               
        from /opt/ruby1.8/lib/ruby/gems/1.8/gems/searchlogic-2.4.19/lib/searchlogic/named_scopes/association_conditions.rb:19:in `method_missing' 
        from /opt/ruby1.8/lib/ruby/gems/1.8/gems/searchlogic-2.4.19/lib/searchlogic/named_scopes/association_ordering.rb:27:in `method_missing'   
        from /opt/ruby1.8/lib/ruby/gems/1.8/gems/searchlogic-2.4.19/lib/searchlogic/named_scopes/ordering.rb:30:in `method_missing'               
        from /opt/ruby1.8/lib/ruby/gems/1.8/gems/searchlogic-2.4.19/lib/searchlogic/named_scopes/or_conditions.rb:28:in `method_missing'          
        from /opt/ruby1.8/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:1959:in `method_missing_without_paginate'           
        from /opt/ruby1.8/lib/ruby/gems/1.8/gems/will_paginate-2.3.12/lib/will_paginate/finder.rb:170:in `method_missing'                         
        from /opt/ruby1.8/lib/ruby/gems/1.8/gems/acts_as_commentable-3.0.0/lib/comment_methods.rb:12:in `included'                                
        from .../app/models/comment.rb:2:in `include'                                                           
        from .../app/models/comment.rb:2                                                                        
        from /opt/ruby1.8/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'                                          
        from /opt/ruby1.8/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'...

现在在我看来,acts_as_commentable gem 导致了这种情况。但为什么在开发模式下却运行得很好呢。

Everything works fine in development mode, but when I try to start my app in production mode (RAILS_ENV=production script/server) I get the following error:

/opt/ruby1.8/lib/ruby/gems/1.8/gems/searchlogic-2.4.19/lib/searchlogic/named_scopes/conditions.rb:81:in `method_missing': protected method `scope' called for #<Class:0x7f41de524410> (NoMethodError)                                                                                               
        from /opt/ruby1.8/lib/ruby/gems/1.8/gems/searchlogic-2.4.19/lib/searchlogic/named_scopes/association_conditions.rb:19:in `method_missing' 
        from /opt/ruby1.8/lib/ruby/gems/1.8/gems/searchlogic-2.4.19/lib/searchlogic/named_scopes/association_ordering.rb:27:in `method_missing'   
        from /opt/ruby1.8/lib/ruby/gems/1.8/gems/searchlogic-2.4.19/lib/searchlogic/named_scopes/ordering.rb:30:in `method_missing'               
        from /opt/ruby1.8/lib/ruby/gems/1.8/gems/searchlogic-2.4.19/lib/searchlogic/named_scopes/or_conditions.rb:28:in `method_missing'          
        from /opt/ruby1.8/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:1959:in `method_missing_without_paginate'           
        from /opt/ruby1.8/lib/ruby/gems/1.8/gems/will_paginate-2.3.12/lib/will_paginate/finder.rb:170:in `method_missing'                         
        from /opt/ruby1.8/lib/ruby/gems/1.8/gems/acts_as_commentable-3.0.0/lib/comment_methods.rb:12:in `included'                                
        from .../app/models/comment.rb:2:in `include'                                                           
        from .../app/models/comment.rb:2                                                                        
        from /opt/ruby1.8/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'                                          
        from /opt/ruby1.8/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'...

Now it seems to me it that the acts_as_commentable gem is causing this. But how come, it works fine in development mode.

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

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

发布评论

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

评论(2

暮年 2024-09-07 22:45:43

在开发模式下,类会根据需要加载。在生产中,它们在 Rails 启动时被缓存。

in development mode classes are loaded as you need them. In production, they're cached when rails starts.

给我一枪 2024-09-07 22:45:43

感谢 fl00r 的评论,我发现了错误:

显示comment.rb(第2行附近)

comment.rb 中的第 2 行是 include ActsAsCommentable::Comment。这对我来说有点奇怪,所以我查看了acts_as_commentable gem 的官方文档。这就是问题所在。它应该是 acts_as_commentable 。一定是从某个地方复制粘贴的。

尽管如此,它如何在开发模式下工作仍然是个谜。因为annaswims提到的类缓存?

I have found the error thanks to fl00r's comment:

show comment.rb (around line 2)

Line 2 in comment.rb was include ActsAsCommentable::Comment. That seemed a bit strange to me, so I took a look at the official documentation for the acts_as_commentable gem. That was the problem. It should have been acts_as_commentable instead. Must have copy-pasted it from somewhere.

Still, the mystery remains how it could have worked in development mode. Because of the class caching mentioned by annaswims?

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