Rake任务错误:未初始化的常量==模型/控制器类未加载

时间:2014-02-18 22:10:18

标签: ruby-on-rails ruby-on-rails-3 rake

在Rails 3.2.16中,此rake任务的执行因uninitialized constant错误而中断,抱怨Model类MyModel未知。

  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

1 个答案:

答案 0 :(得分:0)

看起来根本原因是我在配置文件中启用了config.threadsafe!

要解决此问题,请执行以下操作:

  # 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