Reputation: 13243
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
Reputation: 3803
add this line to application.rb
config.autoload_paths += Dir["#{config.root}/lib/**/"]
Upvotes: 2