我有一个Rails应用程序和一个引擎。
当我的环境/ production.rb中的config.eager_load = true时,应用程序崩溃,在引擎中出现以下错误
FATAL: ActionView::Template::Error(undefined local variable or method `current_user' for #<#<Class:0x00000005812fe0>:0x00000005811e88>)
/var/www/rack_apps/manager/shared/vendor_bundle/ruby/2.1.0/gems/authorization_engine-0.1.0.SNAPSHOT.20140407182910/app/views/authorization_engine/authorizations/new.html.haml:26:in `__var_www_rack_apps_manager_shared_vendor_bundle_ruby_______gems_authorization_engine_______________________________app_views_authorization_engine_authorizations_new_html_haml__268041456534634533_46121540'
vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.4/lib/action_view/template.rb:143:in `block in render'
vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/notifications.rb:161:in `instrument'
vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.4/lib/action_view/template.rb:141:in `render'
vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.4/lib/action_view/renderer/template_renderer.rb:49:in `block (2 levels) in render_template'
vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.4/lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/notifications.rb:159:in `block in instrument'
vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/notifications.rb:159:in `instrument'
vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.4/lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.4/lib/action_view/renderer/template_renderer.rb:48:in `block in render_template'
vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.4/lib/action_view/renderer/template_renderer.rb:56:in `render_with_layout'
vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.4/lib/action_view/renderer/template_renderer.rb:47:in `render_template'
vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.4/lib/action_view/renderer/template_renderer.rb:17:in `render'
vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.4/lib/action_view/renderer/renderer.rb:42:in `render_template'
vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.4/lib/action_view/renderer/renderer.rb:23:in `render'
vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.4/lib/abstract_controller/rendering.rb:127:in `_render_template'
vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.4/lib/action_controller/metal/streaming.rb:219:in `_render_template'
vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.4/lib/abstract_controller/rendering.rb:120:in `render_to_body'
vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.4/lib/action_controller/metal/rendering.rb:33:in `render_to_body'
vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.4/lib/action_controller/metal/renderers.rb:26:in `render_to_body'
但如果我设置config.eager_load = false
,上面的内容似乎也有效这是正常的吗? ...我知道你不应该在生产中将eager_load设置为false。有没有办法不急于加载引擎或让我的整个概念错了?
我知道它表示未定义的变量current_user但是当我在本地运行时它会完美地拾取它。任何建议或想法都会很棒。谢谢
答案 0 :(得分:0)
http://edgeguides.rubyonrails.org/configuring.html
官方文件说: config.eager_load为true时,eager加载所有已注册的config.eager_load_namespaces。这包括您的应用程序,引擎,Rails框架和任何其他已注册的命名空间。
要回答这个问题,我们需要知道您在会话中使用了什么,例如设计宝石或其他东西。但是我想你使用了一些gem,如果你说本地你的应用程序运行没有错误,那么你的宝石版本在本地和服务器上是否有区别?你可以更新gem,例如它破坏了一些东西。所以我建议你从这开始。