【发布时间】:2018-09-20 16:21:33
【问题描述】:
所以我正在尝试创建两封电子邮件。当餐厅至少有一个订单 (orders_of_the_day) 时,它会发送一个到餐厅,否则它会发送其他订单 (no_order_today)。
orders_of_the_day 案例效果很好。第二个没有:当我在本地运行RestaurantMailer.no_order_today 时出现以下错误:
(对象不支持#inspect)
这是我的 restaurant_mailer.rb 文件:
class RestaurantMailer < ApplicationMailer
default from: 'noreply@takeameal.fr'
def self.send_orders_of_the_day
@restaurants = Restaurant.where(vacation_mode: false)
@restaurants.each do |r|
@meal = Meal.find_by(restaurant_id: r[:id], week_day: Date.today.cwday)
@orders = Order.where("created_at >= :start_time and meal_id = :meal", start_time: DateTime.new(Date.today.year, Date.today.month, Date.today.day, 13, 0, 0).in_time_zone('Paris').prev_day, meal: @meal.id).order(:pick_up_time)
if !@orders.empty?
orders_of_the_day(r, 'À OUVRIR AVANT 11H30 : COMMANDES TAKE A MEAL ', @meal, @orders).deliver_now
else
no_order_today(r, 'Pas de commandes Take a Meal aujourd\'hui', @meal)
end
end
end
def orders_of_the_day(recipient, shift, meal, orders)
@meal = meal
unless @meal.nil?
@orders = orders
emails = [recipient[:email], recipient[:email2], recipient[:email3]].delete_if { |email| email.empty? }
mail(to: emails, subject: shift)
end
end
def no_order_today(recipient,shift, meal)
@meal = meal
emails = [recipient[:email], recipient[:email2], recipient[:email3]].delete_if { |email| email.empty? }
mail(to: emails, subject: shift)
end
end
知道为什么我会得到这个以及如何解决它吗?
【问题讨论】:
-
你没有在
no_order_today中调用deliver_now -
确实...我实际上是首先在控制台中对其进行测试...现在有意义了。非常感谢您的帮助@PardeepDhingra!
标签: ruby-on-rails ruby mailer