0

We just updated to Rails 5.

All tests now pass. I'm able to spin up a web server and everything appears to work. But over on the production server, some URLs give an error like this:

uninitialized constant #<Class:0x0055b8d9dedf68>::JsonUtils
app/models/thing.rb:71:in `as_json'

JsonUtils lives in app/lib/json_utils.rb. (We moved them to app/lib when lib was taken out of the autoload paths in the past.)

If I run bin/rails console development, and actually, even if I run bin/rails console production, I can type JsonUtils and it resolves fine. Yet when the application is running for real, this class can't be resolved.

Has anyone else seen something like this?

Hakanai
  • 12,010
  • 10
  • 62
  • 132
  • 1
    Can you please post your `Thing` class? I would guess when you prepend `JsonUtils` with `::` like `::JsonUtils` it will work. But to know for shure I need to see your class definistion. – slowjack2k Sep 26 '16 at 05:22
  • Maybe you must user eager_load_path: http://blog.arkency.com/2014/11/dont-forget-about-eager-load-when-extending-autoload – kunashir Sep 26 '16 at 05:55
  • @slowjack2k hmm, I didn't think of that. No, we're definitely not prefixing it like that. Can you explain why that would be required only in production? I'm not particularly fond of things behaving differently in production from every other environment, because it defeats the purpose of having tests... – Hakanai Sep 26 '16 at 23:55
  • @kunashir I discovered that setting while I was digging around, but [according to another answer](http://stackoverflow.com/a/19852844/138513), it's only needed if you're also manipulating autoload_paths, which we are not anymore. The prefixing thing in the other comment might be on the right track... I'll have to spin up a production environment of my own somehow... the real one I don't have access to. :/ – Hakanai Sep 27 '16 at 00:00
  • You have to keep in mind that Rails development mode is slightly different as the production mode. If you don't want it, you have to configure production and development mode exactly the same. But in this case you have always to restart your server when you changed a file. Your issue has some thing to do with Rails autoload feature. In some cases it does not work in production like it did in development. I think it happens because in production mode all classes are preloaded. – slowjack2k Sep 27 '16 at 07:40
  • In an annoying twist, it turns out that after spending a whole day getting docker to load a production environment, the issue doesn't happen on *my* production environment, only the one being run by IT. So now I'm in a situation where if they had agreed to use docker as initially suggested, it would be working, but because they're using some Amazon rubbish, it isn't. – Hakanai Sep 27 '16 at 23:49

0 Answers0