0

我在我的 RakeFile 中添加了一个新任务(我知道这样做的新方法是将您的任务添加到 lib/tasks,但其他任务在 RakeFile 中,我还不想重构。)我添加的任务访问模型(尽管模型名称不在错误中)但不会访问其方法。

rake aborted!
undefined method `transcode' for #<Class:0x10700e878>

我在 RakeFile 中的任务非常简单;

namespace :casta do
  desc "Transcode user videos from S3"
  task :transcode => :environment do
    ProfileVideo.transcode
  end
end

我的模型非常简单;

class ProfileVideo < ActiveRecord::Base

  belongs_to :application_form

  def transcode
    puts "Transcoding"
  end

end

我的其他 RakeFile 任务使用脚本/运行程序,它们工作得很好。

rails
2.3.14 rake 0.8.7(我在 0.9.2 虽然降级测试)

想要一些见解,谢谢。

4

1 回答 1

2

您将 transcode 作为类方法调用,因此将 transcode 方法更改为:

  def self.transcode
    puts "Transcoding"
  end

或者更可能是您想要的:您可以创建一个 ProfileVideo 实例并在其上调用 transcode ,然后将 transcode 方法保持原样:

  task :transcode => :environment do
    pv = ProfileVideo.new(attributes)
    pv.transcode
  end
于 2013-01-14T23:38:13.143 回答