Mandrill API模板

时间:2013-02-26 16:52:12

标签: ruby-on-rails ruby email heroku mandrill

我正在使用Mandrill的Ruby API Gem并使用以下简单模板进行测试:

<html>

    <body>
        <h1 mc:edit="header">testastic</h1>
        <hr/>
        <br/><br/>
        <div mc:edit="main_section"></div>
        <hr/>
        <div mc:edit="footer"></div>
    </body>
 </html>

按照Heroku指南中的示例,我有以下Ruby代码:

require 'mandrill'
  m = Mandrill::API.new
  rendered = m.templates.render 'test-template', [{:header => 'some header text', :main_section => 'The main content block', :footer => '<h3>asdf</h3>'}]

  mail(:to => "Jayson Lane <jayson@domain.com>", :subject => "Test Email") do |format|
       format.html { rendered['html'] }
       #format.text { render "test" }
  end

这很好用,电子邮件发送我的模板很好,但是,它不会取代模板mc:edit变量。我错过了什么吗?

1 个答案:

答案 0 :(得分:9)

您需要为要替换的每个元素构造一个哈希值。例如,我在模板中有这个:

   <h3 mc:edit="plan_info_name"> </h3>
   <span mc:edit="plan_info_description"> </span>
   <span mc:edit="plan_info_benefits"> </span>

这是邮寄的:

mandrill.messages.send_template(template,[
    {
     :name => 'plan_info_name',
     :content => extra[:membership_info].name
    },
    {
     :name => 'plan_info_description',
     :content => extra[:membership_info].long_description   
    },
    {
     :name => 'plan_info_benefits',
     :content => benefits_list 
    }
  ....