【问题标题】:Object doesn't support #inspect with Mandrill对象不支持 #inspect with Mandrill
【发布时间】:2015-03-03 23:10:07
【问题描述】:

我正在尝试让 Mandrill API 与我的 Rails 应用程序一起使用,但是当我尝试在控制台中使用以下命令对其进行测试时:

AdminMailer.new_attending(creator, user)

我得到以下信息:

AdminMailer#new_attending: processed outbound mail in 1.8ms
(Object doesn't support #inspect)
=>  

我正在关注如何从这里集成它的教程:https://gorails.com/episodes/sending-emails-with-mandrill 但我似乎无法找到错误所在。

我的邮件代码是:

class AdminMailer < ApplicationMailer

require 'mandrill'

 def mandrill_client
  @mandrill_client ||= Mandrill::API.new MANDRILL_API_KEY
 end

 def new_attending(creator, user)
  template_name = "new-attending"
  template_content = []
   message = {
   to: [{email: creator.email, name: creator.name}],
   subject: "Someone wants to go riding with you!",
   merge_vars: [
     {rcpt: creator.email,
     vars: [
       {name: "CREATOR_NAME", content: creator.name},
       {name: "USER_NAME", content: user.name},
       {name: "USER_NUMBER", content: user.number}
       ]}
   ]
 }
 mandrill_client.message.send_template template_name, template_content, message
end

end

User.rb 模型:

class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable,
     :omniauthable, :omniauth_providers => [:facebook]

has_many :events

has_many :attending_events
has_many :attending, through: :attending_events, source: :event

has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" },   :default_url => "/images/:style/missing.png"
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/

我的 event.rb 模型:

class Event < ActiveRecord::Base

belongs_to :user

has_many :attending_events
has_many :attendees, through: :attending_events, source: :user

end

有谁知道问题可能来自哪里以及如何解决?在控制台中,我可以很好地获取 creator.email、creator.name、user.name 和 user.number,但是当我尝试将它们放入邮件程序时,它不起作用。

提前致谢!!

【问题讨论】:

  • 问题解决了吗?
  • 评论你为 while 设计代码并检查此错误是否已解决

标签: ruby-on-rails mandrill


【解决方案1】:

您在任何地方都无法在 new_attending(creator,user) 方法中获取模型数据。

从您的邮件中删除悲伤的代码,使用下面提供的快乐代码:)

@mandrill = nil
def default
    require 'mandrill'
    @mandrill = Mandrill::API.new 'Enter your API Key'
end

def new_attending(creator_name,creator_email,user_name)
default
----your code --
end

在 Event.rb 中添加这个。

class Event < ActiveRecord::Base

--
---
    def send_new_attending_mail_notification
         creator_name = self.name
         creator_email = self.email
         user_name = self.user.name
         AdminMailer.new.new_attending(creator_name,creator_email,user_name)
    end
end

从您的事件控制器调用此方法,

@event.send_new_attending_mail_notification

如果您在这方面遇到任何问题,请告诉我。

【讨论】:

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