Cat*_*ish 5 ruby-on-rails actionmailer ruby-on-rails-3
我有一个邮件发送器,可以在日志中看到它正在发送,但是邮件正文中没有包含邮件发送器视图中的任何内容。
这是由于我已将内容放入子文件夹,并且尝试:template_path在mail函数中使用,但无济于事。
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
Run Code Online (Sandbox Code Playgroud)
/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>
Run Code Online (Sandbox Code Playgroud)
我注意到devise在/ views / devise / mailers / ...中有邮件视图,所以我知道这是可能的,但是我不确定如何。
我今天回到这个项目,似乎发现今天的模板没有问题,无需指定 template_path。
尽管令人悲伤,但显然我所需要做的就是停止并重新启动我的服务器,以便我的邮件程序视图能够被拾取。由于无需停止和启动我的服务器即可获取其他视图,因此我对此感到非常惊讶。