uninitialized constant SampleController ::执行delayed_job worker方法时延迟

时间:2013-07-20 11:16:15

标签: ruby-on-rails delayed-job

执行SampleController时出现以下错误。

uninitialized constant IdeasController::Delayed

我已经使用rake jobs启动了delayed_job:work。我在SampleController.rb中有以下delayed_job代码

Delayed::Job.enqueue(DelayedWorker.new({:model=>object.class.to_s,:object_id=>object.id,:meth=>:create_suggestion}))

delayed_worker.rb包含以下代码:

class DelayedWorker < Struct.new(:options)

  def perform

    if obj=Object.const_get(options[:model]).find(options[:object_id])

      if (options[:para] ? obj.send(options[:meth],options[:para].first) : obj.send(options[:meth]))
        puts "Successfull"
      else
        puts "Failed"
      end
    end
  end
end

任何人请帮我解决这个问题。

...谢谢

1 个答案:

答案 0 :(得分:0)

更改

Delayed::Job.enqueue(DelayedWorker.new({:model=>object.class.to_s,:object_id=>object.id,:meth=>:create_suggestion}))

::Delayed::Job.enqueue(DelayedWorker.new({:model=>object.class.to_s,:object_id=>object.id,:meth=>:create_suggestion}))