Mailer没有加载到Mongoid的Rake任务中

时间:2013-09-03 06:11:02

标签: ruby-on-rails-3 mongoid rake-task mailer

我正在尝试使用Rake任务发送邮件。它在开发环境中工作正常,但不能在分段中工作。

不断发出以下错误 - 未初始化的常量ReservationMailer

感谢任何帮助。

LIB /任务/ reminders.rake

namespace :reservations do
  desc 'send reservation reminder mail to customers'
  task :reminder => :environment do
    reservations = Reservation.tomorrow
    reservations.each { |reservation| reservation.send_reservation_reminder_mail }
  end
end

应用程序/模型/ reservation.rb

 class Reservation
   include Mongoid::Document
   include Mongoid::Timestamps::Short

   ...

   def send_reservation_reminder_mail
     ::ReservationMailer.customer_reservation_reminder(self).deliver
   end
 end

应用程序/邮寄者/ reservation_mailer.rb

class ReservationMailer < ActionMailer::Base
  def customer_reservation_reminder(reservation)
    mail to: reservation.customer.email, subject: 'Reminder'
  end
end

1 个答案:

答案 0 :(得分:0)

我会说你在类名或文件名上有一个拼写错误的名字,因此rails无法找到Mailer。测试它的另一种方法是启动一个rails c并键入ReservationMailer以查看是否存在常量。