对象不支持Mandrill的#inspect

时间:2015-01-06 09:50:19

标签: ruby-on-rails mandrill

我正在尝试使用我的Rails应用程序使用Mandrill API,但是当我尝试在控制台中测试它时:

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,但是当我尝试将它们放入邮件程序时,它不起作用。

提前致谢!!

1 个答案:

答案 0 :(得分:-1)

您无法在 new_attending(创建者,用户)方法中获取模型数据。

从邮件程序中删除令人遗憾的代码,使用下面提供的快乐代码:)

@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

如果你遇到任何问题,请告诉我。