【发布时间】:2015-06-02 10:32:15
【问题描述】:
我有一个 Ruby on Rails 应用程序,我正在编写我的邮件程序以将 SMTP 标头发送到 Mandrill。 我想我在将变量放入字符串时遇到问题:
class MyMailer < Devise::Mailer
helper :application # gives access to all helpers defined within `application_helper`.
include Devise::Controllers::UrlHelpers # Optional. eg. `confirmation_url`
def confirmation_instructions(record, token, opts={})
headers['X-MC-MergeVars'] = '{"ctoken1": "Drip Email"}'
temp_var = "Hello Everyone"
headers['X-MC-MergeVars'] = '{"tag_test_1": "yoyoyo"}' # 1
# headers['X-MC-MergeVars'] = "{'tag_test_1': 'yoyoyo'}" # 2
# headers['X-MC-MergeVars'] = "{'tag_test_1': #{temp_var}}" # 3
# headers['X-MC-MergeVars'] = '{"tag_test_1": #{temp_var}}' # 4
headers['X-MC-MergeVars'] = '{"ctoken3": "Test at the End"}'
super
end
end
我想将“temp_var”变量放入标题中。你可以看到我的 4 次尝试。
首先 - 健全性检查 - #1 中的语法工作正常 - 我的 mandrill 电子邮件中的变量“tag_test_1”被替换为“yoyoyo”,但当然这不是使用 ruby 变量。
我的尝试 2,3 或 4 均无效。我的 Mandrill 电子邮件收到 TAG_TEST_1 而不是变量替换(“大家好”)。
我最终要做的是通过 Mandrill 将帐户激活链接放入电子邮件中。所以我想我需要发送“令牌”变量,但现在我似乎无法获得一个已知变量 (temp_var) 来传递给电子邮件。
我怀疑我没有正确理解 Ruby 字符串语法。
任何帮助表示赞赏!
【问题讨论】:
标签: ruby string smtp mandrill mailer