0

我有这样的课

class RecurringJob
  include ScheduledJob

  run_every 1.hours

  def perform
    puts "perform job"
  end
end

我收到一条错误消息:

预期 D:/ASM/source/app/lib/jobs/scheduled_job.rb 来定义 ScheduledJob

文件定义是这样的:

module Delayed
 module ScheduledJob

def self.included(base)
  base.extend(ClassMethods)
  base.class_eval do
    @@logger = Delayed::Worker.logger
    cattr_reader :logger
  end
end
    ....

 end
end

错误是什么意思?这不是一个定义吗?

编辑

我你必须知道,这个类是在一个 rake 任务中定义的(除了这个类之外它是空的,我不知道这是否允许)。

更详细的错误:

Expected D:/ASM/source/app/lib/jobs/scheduled_job.rb to define ScheduledJob
D:/Software/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:503:in `load_missing_constant'
D:/Software/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:192:in `block in const_missing'
D:/Software/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:190:in `each'
D:/Software/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:190:in `const_missing'
D:/Software/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:514:in `load_missing_constant'
D:/Software/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:192:in `block in const_missing'
D:/Software/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:190:in `each'
D:/Software/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:190:in `const_missing'
D:/ASM/source/app/lib/tasks/sandbox.rake:29:in `<class:RecurringJob>'
D:/ASM/source/app/lib/tasks/sandbox.rake:28:in `block in <top (required)>'
4

1 回答 1

1

Rails 遵循非常严格的命名约定,其中包括 lib 文件。

如果要在 Delayed 模块中定义 ScheduledJob 模块,则必须将文件命名为/lib/delayed/scheduled_job.rb

这将使 Rails 的期望和你的命名相匹配。

于 2013-03-18T16:09:50.853 回答