2

我有一个模型 screenshot.rb。

将以下定义为 rake 任务

namespace :clean_up_temp do
  desc "clean up unsaved screenshots 1 hours ago"
  task :screenshots => :environment do
    Screenshot.destroy_all([ 'created_at<? AND title IS NULL', 1.hours.ago ])
  end   
end

它在本地运行良好。

在 Heroku 上失败

Running `rake clean_up_temp:screenshots` attached to terminal... up, run.2861
rake aborted!
uninitialized constant Screenshot
/app/lib/tasks/clean_up_temp_screenshots.rake:3:in `block in <top (required)>'
/app/lib/tasks/clean_up_temp_screenshots.rake:1:in `<top (required)>'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:641:in `block in run_tasks_blocks'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:641:in `each'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:641:in `run_tasks_blocks'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:244:in `run_tasks_blocks'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:446:in `load_tasks'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
/app/Rakefile:6:in `<top (required)>'
(See full trace by running task with --trace)

我也试过添加

config.dependency_loading = true if $rails_rake_task

在生产中.rb

我怎么解决这个问题

4

0 回答 0