Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4 uninitialized constant for module

In a new rails 4 app I anm getting an unintialized constant error for a module. The module is named ProcessBill and is located in lib/process_bill.rb

console error:

ActionController::RoutingError (uninitialized constant BillsController::ProcessBill): 

controller code:

class BillsController < ApplicationController    include ProcessBill 

lib/process_bill.rb

module ProcessBill 
like image 430
markhorrocks Avatar asked Jun 09 '13 08:06

markhorrocks


2 Answers

Have you added lib to your autoload path? This was necessary in Rails 3, I'm not sure if it's still required for Rails 4.

Try adding this into the class definition in config/application.rb -

    config.autoload_paths += %W(#{config.root}/lib) 
like image 121
sevenseacat Avatar answered Sep 27 '22 21:09

sevenseacat


I had this problem too with the lib directory with Rails 5 and it appeared in production but not in development. To fix it you need to add the lib directory to eager_load_paths. Here is the relevant part from my application.rb:

config.autoload_paths << "#{Rails.root}/lib" config.eager_load_paths << "#{Rails.root}/lib" 
like image 40
Peter Marklund Avatar answered Sep 27 '22 21:09

Peter Marklund