Joshua Muheim
Joshua Muheim

Reputation: 13243

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

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.

Upvotes: 0

Views: 146

Answers (1)

Vrushali Pawar
Vrushali Pawar

Reputation: 3803

add this line to application.rb

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

Upvotes: 2

Related Questions