(对象不支持 #inspect) 对于邮件轨道



所以我正在尝试创建两封电子邮件。当餐厅至少有一个订单(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

关于我为什么得到这个以及如何解决它的任何想法?

正如@Pardeep Dhingra在评论中提到的,我需要打电话给deliver_now以便发送邮件。

在控制台中运行RestaurantMailer.no_order_today(recipient, shift, meal)也不起作用。所以正确的答案是:

  • RestaurantMailer.no_order_today(recipient, shift, meal).deliver_now在控制台中进行测试

  • no_order_today(r, 'Pas de commandes Take a Meal aujourd'hui', @meal).deliver_now在我的代码中。

最新更新