(对象不支持#inspect)用于邮件Rails

时间:2018-09-19 15:09:58

标签: ruby-on-rails ruby mailer

所以我正在尝试创建两封电子邮件。一个餐馆至少有一个订单时将其发送到饭店(orders_of_the_day),否则将另一个餐馆发送(no_order_today)。

当天的订单情况很好。第二个错误:在本地运行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

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

1 个答案:

答案 0 :(得分:0)

正如@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在我的代码中。