I have some custom classes/modules defined under /app/lib.
I have a Rake task, via whenever, that tries to load the environment then execute one of the class methods.
Here’s an example of the rake task:
namespace :box do
task :fetch => :environment do
BoxInterface::Tasc::Fetcher.fetch
end
end
If I run BoxInterface::Tasc::Fetcher.fetch from the Rails console, it works fine.
If I run bundle exec rake 'box:fetch' I get this error:
uninitialized constant BoxInterface::Tasc
The file structure under lib is:
/app/lib/box_interface/tasc/fetcher.rb
The odd thing here is that we have a staging server that this code works fine under. Does this have something to do with the environment? I am unsure how to troubleshoot this.
Have you added the folders in your lib directory to your autoload path in your
application.rbfile? You might have to do that if you’re using Rails 3.0 or greater.Try adding this line:
inside of your class definition (
class Application < Rails::Application) in theapplication.rbfile.