Welcome to Working With Rails


Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
undefined method 'send_later' in delayed_job
4 Posts
undefined method 'send_later' in delayed_job

Hi Am using delayed_job for long run background operations.In my app while click on "Approve" button then send mails to users .

But am getting following error

ctionView::TemplateError (undefined method `send_later' for Notification:Class) on line #10 of app/views/flagshipdeals/approve.rjs: 7: users = User.find_by_sql(sql) 8: if users != [] 9: users.each do |u| 10: Notification.send_later(:deliver_deal_of_the_day_mailer, u,@deal)

11: end

My controller I written code is

  Notification.send_later(:deliver_deal_of_the_day_mailer, u,@deal)

and I have Notification.rb code is class Notification < ActionMailer::Base def deal_of_the_day_mailer(user,deal)

@subject     = "#{deal.head_line.gsub(/]*>/,  "")}"
@body[:url]  = "#{SITE_URL}/"
@body["deal"]  = deal

end protected def setup_email(user)

@recipients  = "#{user.login}"
@from        = "#{YOURSITE}"
@sent_on     = Time.now
@body[:user] = user
@content_type = "text/html"

end end

I ran rake jobs:work to start jobsworks . Can anybody help me please

Forum Rating: 50
Sign In To Rate Post

lucky, Your Notification class isn't a Delayed::Job class. See at line #10. You're trying to call send_later from Notification which is an action mailer and it's not supposed to have this method.

Yes .IT's not the action -mailer method.But in delayedjob plugin gives the methos send_later.How to call this

Forum Rating: 50
Sign In To Rate Post

Look at this:


The "send_later" seems like an instance method, not a class method. You have to call it over a concrete instance of Notification, not directly on the class... ;-)

4 Posts
Login to add your message