Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 - Delayed_Job (collectiveidea), trying to Delay Mailers - Error: NoMethodError (undefined method `delay' for UserMailer:Class)

I'm using the delayed_job gem here: https://github.com/collectiveidea/delayed_job

I have the following in an observer:

UserMailer.delay.msg_notification(record) 

In user_mailer.rb

class UserMailer < ActionMailer::Base 
... 
def msg_notification(record) 
    mail( 
          :to => "#{record.user.email}", 
          :subject => "Notification" 
          ) 
  end 
.. 
end 

But this errors with:

 NoMethodError (undefined method `delay' for UserMailer:Class): 

Any ideas? thanks

like image 515
AnApprentice Avatar asked Dec 11 '10 20:12

AnApprentice


2 Answers

I've seen a problem like this on our Rails app (2.3.8, but the issue sounds the same). Basically, there are three ways to delay an action:

  1. MyClass.delay.foo(arg)
  2. Putting handle_asynchronously :foo in your class definition after the definition of foo
  3. MyClass.send_later(:foo, arg)

For whatever reason, #3 was the only form that worked consistently across all our development machines. #1 died on our development server (Ubuntu); #2 on our designer's Mac. But #3 was fine.

Hope that helps!

like image 112
Xavier Holt Avatar answered Nov 15 '22 10:11

Xavier Holt


Also check if you have restarted your server after the bundle install. That could be a issue too...

like image 30
Kunday Avatar answered Nov 15 '22 12:11

Kunday