Rake Task in Rails 3 on Production ENV
Cannot execute Rake Task in production environment? Does it throws errors of uninitialized objects or refuses to load Model classes?
To execute a rake task for eager loading we require,
config.threadsafe! to be disabled in production which is enabled by default.
But our requirement is to get it disabled only on running a rake task.
Rake already sets a Ruby global: $rails_rake_task
So, in config/environments/production.rb, just say:
config.threadsafe! unless $rails_rake_task
Hello,
I have exactly the same problem that you wrote some lines before.
My required model is on a gem and even if I change config.threadsafe as you said, nothing works and the model is still “uninitialized constant”.
I tried a lot of things and followed a lot of tutorials like this one :
http://stackoverflow.com/questions/4300240/rails-3-rake-task-cant-find-model-in-production
Do you have any idea ?
Thank you in advance.
Did you require the environment on your rake task like,
task :name_of_task => :environment do
end