Poetry of Programming

Its about Ruby on Rails – Kiran Soumya

By

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

2 Responses to Rake Task in Rails 3 on Production ENV

  1. Brice says:

    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.

  2. kiran says:

    Did you require the environment on your rake task like,

    task :name_of_task => :environment do

    end

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>