【发布时间】:2013-12-19 01:56:46
【问题描述】:
我可以在日志中看到一个邮件程序正在发送,但邮件正文不包含邮件程序视图中的任何内容。
这是因为我将东西放在子文件夹中,并且我尝试在我的 mail 函数中使用 :template_path 但无济于事。
app/mailers/marketing/marketing_mailer.rb
class Marketing::MarketingMailer < ActionMailer::Base
require 'mail'
address = Mail::Address.new "test@example.com" # ex: "john@example.com"
address.display_name = "Text" # ex: "John Doe"
# Set the From or Reply-To header to the following:
address.format # returns "John Doe <john@example.com>"
default from: address
# Sends an email when someone fills out the contact form
def contact(name, email, message)
@name = name
@email = email
@message = message
mail(:subject => "Test", :to => 'test@example.com', :reply_to => @email) # <== I've tried using :template_path => 'marketing', 'marketing/marketing_mailer', etc, but none worked.
end
end
/app/views/marketing/marketing_mailer/contact.html.erb
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
</head>
<body>
<p>Name: <%= @name %></p>
<p>Email: <%= @email %></p>
<p>Message: <%= @message %></p>
</body>
</html>
我注意到 devise 在 /views/devise/mailers/... 中有邮件视图,所以我知道这是可能的,但我不确定如何。
【问题讨论】:
-
这取决于您使用的 Rails 版本。请提及您的 Rails 版本
-
@SatyaKalluri 我看到了那个答案并尝试了 template_path。其他一些答案似乎引发了弃用警告和其他东西。
标签: ruby-on-rails ruby-on-rails-3 actionmailer