Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 5 ignoring /lib class?

Tags:

I've used this method for modals in rails. It works really well, but I've just upgraded to Rails 5 beta3, and now it's not working in production.

I get this error:

Completed 500 Internal Server Error in 22ms (ActiveRecord: 0.9ms)  NameError (uninitialized constant ApplicationController::ModalResponder):  app/controllers/application_controller.rb:26:in `respond_modal_with' app/controllers/tools_controller.rb:28:in `new' 

Is my inheritance thrown off with Rails 5?

My class ModalResponder < ActionController::Responder is in /lib and works in development...

Looking for info on changes with rails 5, but sources are limited to my knowledge.

like image 388
Kevin Brown Avatar asked Apr 05 '16 18:04

Kevin Brown


2 Answers

In config/application.rb, change this:

config.autoload_paths << Rails.root.join('lib') 

to this:

config.eager_load_paths << Rails.root.join('lib') 

eager_load_paths will get eagerly loaded in production and on-demand in development. Doing it this way, you don't need to require every file explicitly.

See more info on this answer.

like image 69
Jonathan Tran Avatar answered Oct 05 '22 09:10

Jonathan Tran


You need to add a 'require' (on application.rb) with your classes inside the lib folder.

Like:

require './lib/someclass'

I recommend you put it inside a Rails plugin.

like image 45
Alvaro Cantador Avatar answered Oct 05 '22 09:10

Alvaro Cantador