0

I recently upgraded an old ruby app from rails 5 to rails 7. Ever since, I have been getting this error. It happens after I run rails s and access the application through the browser (seems like the application builds successfully, I only get the error after loading the web App). The constant referred to is defined as such in app\models\faculty_w\v1\appointment.rb :

class FacultyW::V1::Appointment
  include ActiveModel::Validations
  include AppointmentCommon
  include Swagger::Blocks
  include SwaggerSchemas

Anyone have any suggestions?

NameError (uninitialized constant FacultyW::V1::Appointment::SwaggerSchemas):

app/models/faculty_w/v1/appointment.rb:5:in `<class:Appointment>'
app/models/faculty_w/v1/appointment.rb:1:in `<top (required)>'

app/controllers/apidocs_controller.rb:47:in `<class:ApidocsController>'
app/controllers/apidocs_controller.rb:1:in `<top (required)>'

I also tried running zeitwerk:check but I get the same error and no recommendations on how to fix it.

I figured it had something to do with the new autoloader but whenever I add the path to the autoloader in application.rb using config.eager_load_paths += %W(#{config.root}/app/models/faculty_w/v1) and config.autoload_paths += %W(#{config.root}/app/models/faculty_w/v1) I still get the second half of this error.

I also added config.autoloader = :classic to application.rb but that did not change anything

engineersmnky
  • 25,495
  • 2
  • 36
  • 52
  • 1
    It must be some kind of an issue with the new loader. But there are not enough details here for a more precise guess. – Sergio Tulentsev Jul 11 '23 at 13:39
  • What details would you suggest I add – AntonioKaram Jul 11 '23 at 13:42
  • 1
    where is `FacultyW::V1::Appointment::SwaggerSchemas` defined? – AbM Jul 11 '23 at 14:03
  • I just edited the question to include that (looks clearer there) – AntonioKaram Jul 11 '23 at 15:28
  • Rails/Ruby is unable to determine where the `SwaggerSchemas` module is defined. Based on a quick search, it doesn't look like this would be defined by a gem. It would be defined in your codebase. – Richard Jul 11 '23 at 19:13
  • 1
    I would recommend nesting your class e.g. `module FacultyW; module V1; class Appointment; end;end;end`. This will allow `Module.nesting` to work "correctly" or You could try referring to it as a Top Level constant `::SwaggerSchemas` if that is truly where it lives. – engineersmnky Jul 11 '23 at 21:06
  • That worked thank you!!! I changed the module definition to ::SwaggerSchemas – AntonioKaram Jul 12 '23 at 19:12

0 Answers0