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.rb
file? You might have to do that if you're using Rails 3.0 or greater. Try adding this line:
config.autoload_paths += %W(#{Rails.root}/lib/box_interface/tasc)
inside of your class definition ( class Application < Rails::Application
) in the application.rb
file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.