Pregunta

I have added a new task to my RakeFile (I know the new way of doing it is to add your task to lib/tasks, but other tasks are in the RakeFile and I dont wish to refactor just yet.) The task that I added accesses a model (maybe not though as the model name is not in the error) but wont access its method.

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

My task in the RakeFile is pretty simple;

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

And my model is as simple as it gets;

class ProfileVideo < ActiveRecord::Base

  belongs_to :application_form

  def transcode
    puts "Transcoding"
  end

end

My other RakeFile tasks use script/runner and they work perfectly fine.

rails 2.3.14
rake 0.8.7 (I was on 0.9.2 though downgraded to test)

Would love some insight, thanks.

¿Fue útil?

Solución

You're calling transcode as a class method, so change the transcode method to:

  def self.transcode
    puts "Transcoding"
  end

Or more likely what you want: you can create an instance of ProfileVideo and call transcode on that, and leave the transcode method as it is:

  task :transcode => :environment do
    pv = ProfileVideo.new(attributes)
    pv.transcode
  end
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top