1

我正在尝试使用 Rake 任务发送邮件。它在开发环境中运行良好,但在暂存环境中运行良好。

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

任何帮助表示赞赏。

lib/tasks/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
4

1 回答 1

0

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

于 2013-09-03T13:42:58.613 回答