Rails 5 - 电子邮件正文中没有的实例变量

时间:2017-04-28 16:19:31

标签: ruby-on-rails ruby ruby-on-rails-5 mailer

我设置了一封电子邮件,在购买后立即发送,但在电子邮件视图中,变量不会显示。知道为什么吗?

user_mailer文件

def successful_payment(user, product)
    @user = user
    @product = product
    mail(:to => user.email,
        :subject => "Confirmation of payment #{product.name}")
end

payments_controller

def create
    @product = Product.find(params[:product_id])
    @user = current_user
    token = params[:stripeToken]
    # Create the charge on Stripe's servers - this will charge the user's card
    begin
      charge = Stripe::Charge.create(
        :amount => (@product.price * 100).to_i, # amount in cents, again
        :currency => "eur",
        :source => token,
        :description => params[:stripeEmail]
      )
      if charge.paid
        Order.create(product_id: @product.id, user_id: @user.id, total: @product.price)
        UserMailer.successful_payment(@user, @product).deliver_now
      end

模板

<table style="max-width:800px;margin:auto;padding:20px;box-shadow: 0px 1px 4px #000;margin-top:40px;background-color:#f7f7f4;">
  <tbody style="text-align:center;margin:auto;">
    <tr>
      <td><h2 style="color:#625F5F;font-family: 'Open Sans', sans-serif;">Hello <% @user.first_name %></h2></td>

用户名不会出现。

1 个答案:

答案 0 :(得分:4)

这是模板中的错误。语法为bcl = ['Terraza'] class FoundCharacteristicException(Exception): pass for x in li: try: for y in bcl: if y in x: raise FoundCharacteristicException except FoundCharacteristicException: break 以输出文本。 <%= ... %>只运行代码而不输出任何内容。

所以解决方案是:

<% ... %>