I just upgraded to Rails 5.2 and have run into the following issues in development mode, while using a class JsonWebToken
from my app/lib
folder in my ApplicationController
.
NameError - uninitialized constant ApplicationController::JsonWebToken:
Following the directions listed here, I have the following notable things:
- I'm using bootsnap that comes by default with Rails 5.2
- I no longer have a
require
at the top ofApplicationController
since files within theapp
folder seem to be auto-required. - In my
development.rb
, I haveconfig.eager_load = false
. In my
application.rb
, I have the following eager and auto loading code:autoloads lib & policy folder during production config.eager_load_paths << Rails.root.join('lib') config.eager_load_paths << Rails.root.join('policies') #autoloads lib & policy folder during development config.autoload_paths << Rails.root.join('lib') config.autoload_paths << Rails.root.join('policies')
If I remove bootsnap
, then I have to add require 'JsonWebToken'
at the top of ApplicationController
, and then everything works. Bootsnap didn't like that require statement at the top.
I am not sure what is the right way to be creating or using your own classes in Rails 5.2, and to set up so that they are loaded properly in both development and production. I have gone through the Rails docs, but am extremely unclear.