一个Rails 6应用程序在开发模式下运行。
nginx文件从passenger_app_env development;
到passenger_app_env production;
的变化通过sudo nginx -t
然而,在进入域后,在nginx.log
中出现以下错误Error: The application encountered the following error: expected file /home/deploy/fedel/releases/20221105055205/app/controllers/masquerades_controller.rb to define constant MasqueradesController, but didn't (Zeitwerk::NameError)
当返回到开发时,应用程序运行。
控制器内容与宝石devise_masquerade
一致:
class Admin::MasqueradesController < Devise::MasqueradesController
protected
def masquerade_authorize!
authorize(User, :masquerade?) unless params[:action] == 'back'
end
end
所以,是的,控制器没有引用文字常量MasqueradesController
,而是Devise::MasqueradesController
。
为什么开发和生产之间的功能不同?如何才能克服这一点?
Admin::MasqueradesController
的文件应该在子目录app/controllers/admin
中定义,以匹配Admin
的命名空间。
在CI中提前加载是一个很好的实践,可以预见类似这样的事情。测试Rails应用程序指南中有一节给出了一些建议。