Ben Muschol
Ben Muschol

Reputation: 607

Non-deterministic NameError: uninitialized constant on ActiveRecord model

As titled, I'm getting a NameError (uninitialized constant Workflow::Task) for a model defined at app/models/workflow/task.rb.

I'm confident the model definition is correct because it works 90% of the time, but 10% of the time I get this name error and it crashes. I cannot reproduce locally, this only happens in prod, where we use an Amazon Aurora DB. Could this occur if there are issues connecting to the database or something along those lines? Any pointers are appreciated

Using rails 5.1.6.2

Upvotes: 0

Views: 1348

Answers (1)

Ayush Poddar
Ayush Poddar

Reputation: 106

It is clear from the error message that this is not a DB related issue. Put simply, Rails is not loading your model class.

You could try the following:

  1. As @max commented, define your class as module Workflow; class Task.
  2. You could manually add the file in the rails autoload paths. Put this in config/application.rb: config.autoload_paths << Rails.root.join('app/models/workflow')
    • However, this should not be an issue. Rails loads everything within the app directory.

`

Upvotes: 2

Related Questions