rake任务:Class的未定义方法

时间:2013-01-14 23:35:24

标签: ruby-on-rails rake rake-task rakefile

我已经为我的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
耙0.8.7(虽然降级为测试,但我在0.9.2上)

非常喜欢一些见解,谢谢。

1 个答案:

答案 0 :(得分:2)

您将转码称为类方法,因此请将转码方法更改为:

  def self.transcode
    puts "Transcoding"
  end

或者更有可能是你想要的:你可以创建一个ProfileVideo实例并在其上调用转码,并保留转码方法:

  task :transcode => :environment do
    pv = ProfileVideo.new(attributes)
    pv.transcode
  end
相关问题