Rails doesn't seem to load stuff in `lib` directory

83 Views Asked by At

I wanted to refactor some code out of a controller into a module, so I put the file into lib.

# lib/updat_lock.rb
module UpdateLock
  # ...
end

# app/controllers/boilerplates_controller.rb
class BoilerplatesController < InheritedResources::Base
  include UpdateLock
  # ...
end

But sadly, the file doesn't seem to be loaded, as I get an uninitialized constant BoilerplatesController::UpdateLock exception. What's wrong here? I thought the lib folder is always loaded automatically?

Update

Although a solution was provided, the thing I have forgotten was adding a require 'update_lock' on top of my controller file.

1

There are 1 best solutions below

2
On BEST ANSWER

add this line to application.rb

config.autoload_paths += Dir["#{config.root}/lib/**/"]