Home > Net >  Rails production mode encountering a Zeitwerk error
Rails production mode encountering a Zeitwerk error

Time:11-15

A Rails 6 application was in development mode running with passenger.

The change in the nginx file from passenger_app_env development; to passenger_app_env production; passes the sudo nginx -t

However, upon hitting the domain, the following error appears in the 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)

when reverting back into development, the applicatino runs.

The controller's contents are, consistent with the gem devise_masquerade:

class Admin::MasqueradesController < Devise::MasqueradesController
  protected

  def masquerade_authorize!
    authorize(User, :masquerade?) unless params[:action] == 'back'
  end
end

So, yes the controller does not reference the literal constant MasqueradesController but Devise::MasqueradesController.

Why is this functioning differently between development and production? How can this be overcome?

CodePudding user response:

The file for Admin::MasqueradesController should be defined in the subdirectory app/controllers/admin to match the Admin namespace.

It is a good practice to eager load in CI to anticipate anything like this. The Testing Rails Applications guide has a section with some recommendations to put this in place.

  • Related