1

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

/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 导致了这种情况。但是怎么会,它在开发模式下工作正常。

4

2 回答 2

1

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

于 2010-05-12T17:49:15.667 回答
1

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

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

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

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

于 2010-05-12T17:59:28.560 回答