j

Files in /lib not auto loading

James Garcia(jamesgarcia)

I ran into an issue while adding a custom Scrubber. I added the .rb file to my /lib folder, similar to how you have in the Companion app, and I was getting an error "uninitialized constant #<Class:0x008i3455c12345678>::ContentScrubber", where I implemented the custom Scrubber in my view. After some research in Rails 5 there was a change that files in /lib folder will not be auto loaded in production. It looks that it has been change to include development, but I did not find anything saying that. After creating an app/lib folder and moving the custom Scrubber .rb file to that folder it works. Here is a gist that talks about it and links to the Stackoverflow page. I opted for the creating and moving file to app/lib, but not sure if this the best way. I noticed in the companion app you added the line "config.eager_load_paths += %W(#{config.root}/lib)" to overcome this. What are thoughts/suggestions to handle the loading?

  • Nick Haskins replied

    Hey James!

    You're exactly right, in Rails 5 things changed, so adding line in the config for eager loading paths is definitely the right call here.

    FWIW anything under /app will be automatically loaded. You probably know that but just a reminder. I still continue to use /lib though.