0

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.

Ozair Kafray
  • 13,351
  • 8
  • 59
  • 84
user1309480
  • 75
  • 3
  • 7

1 Answers1

1

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.

Radi
  • 696
  • 4
  • 11
  • 2
    discovered it was environment. my config/environments/production.rb file had config.threadsafe! enabled. I commented out this line and now it works!. I did consider add the config.autoload_paths. but I thought loading the environment (e.g. => :environment do) would handle it – user1309480 Aug 27 '12 at 17:51