【问题标题】:(Object doesn't support #inspect) for mailer Rails(对象不支持#inspect)用于邮件Rails
【发布时间】: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


【解决方案1】:

正如 @Pardeep Dhingra 在 cmets 中提到的,我需要致电 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 在我的代码中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-03
    • 2023-02-06
    • 1970-01-01
    • 2015-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-10
    相关资源
    最近更新 更多