0

我有这个位于/lib/jobs/MessageNotificationJob.rb

class MessageNotificationJob < Struct.new(:user_id, :message_id)  

  def perform

        @user = User.find(user_id)
        @message = Message.find(message_id)
    if !message.reciever_open
        MessagesMailer.message_notification(@user, @message ).deliver

    end

  end
end

MessagesController我从with中的方法调用它

Delayed::Job.enqueue(MessageNotificationJob.new(@user.id, @msg.id))

在我的application.rb我有

config.autoload_paths += Dir["#{config.root}/lib/**/"]      

但我得到了错误

 NameError - uninitialized constant MessagesController::MessageNotificationJob:

我该如何解决?我尝试了几种变体,这是最新的变体,作为类似问题的解决方案。我错过了什么?

4

1 回答 1

0

I haven't used the latest DelayedJob, but it looks an awful like the delayed job doesn't have the MessageNotificationJob class loaded when it runs. Try the following:

# file: config/initializers/custom.rb
require 'message_notification_job'

See also this wiki entry -- I think newer versions of DJ improved the error message (rather than silently failing), but the underlying cause is the same.

于 2013-02-19T06:33:18.140 回答