Frage

In Rails 3.2.16 execution of this rake task breaks with uninitialized constant error, complaining that the Model class MyModel is not known.

  desc "some rake task"
  task :do_it => :environment do
    # do something depending on a model:
    MyModel.each do |m|
      # do something with model
    end
    # ...
  end
War es hilfreich?

Lösung

Looks like the root-cause of this is that I had config.threadsafe! enabled in the config files.

To fix this, do this:

  # only enable threadsafe! mode if we are not running rake tasks
  config.threadsafe! unless File.split($0).last == 'rake' # unless it's a rake task
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top