我正在尝试使用 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