没有 Rails 的 ActionMailer - 视图未被拾取
我已经设置了 ActionMailer 3.x 以在 Rails 之外使用,但电子邮件没有正文。有人可以帮忙吗?
# ./app.rb
require 'action_mailer'
ActionMailer::Base.delivery_method = :file
ActionMailer::Base.file_settings[:location] = './tmp/mails'
ActionMailer::Base.view_paths = './views'
class Mailer < ActionMailer::Base
def instructions(email_address)
mail(:to => email_address, :subject => 'hello')
end
end
Mailer.instructions('[email protected]').deliver
然后我有两个文件用于我的视图,一个用于纯文本
# ./views/mailer/instructions.text.erb
These are some instructions
,一个用于 html(使用 HAML - 我知道这存在一些潜在的问题,这里的任何建议也将不胜感激!)
# ./views/mailer/instructions.html.haml
%html
%body
%h1 These are some HTML instructions
但是如果我检查我新创建的 ./tmp/mails/[电子邮件受保护]
我只有以下内容,没有正文:
Date: Wed, 07 Sep 2011 18:38:09 +0530
From: [email protected]
To: [email protected]
Message-ID: <[email protected]>
Subject: hello
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
知道这里发生了什么吗?提前致谢
I've set up ActionMailer 3.x for use outside of Rails, but the emails don't have a body. Can anyone help?
# ./app.rb
require 'action_mailer'
ActionMailer::Base.delivery_method = :file
ActionMailer::Base.file_settings[:location] = './tmp/mails'
ActionMailer::Base.view_paths = './views'
class Mailer < ActionMailer::Base
def instructions(email_address)
mail(:to => email_address, :subject => 'hello')
end
end
Mailer.instructions('[email protected]').deliver
Then I have two files for my views, one for plain text
# ./views/mailer/instructions.text.erb
These are some instructions
And one for html (using HAML - I know there are some potential issues with this, any advice here would be appreciated too!)
# ./views/mailer/instructions.html.haml
%html
%body
%h1 These are some HTML instructions
But if I check my newly created ./tmp/mails/[email protected]
I only have the following, and no body text:
Date: Wed, 07 Sep 2011 18:38:09 +0530
From: [email protected]
To: [email protected]
Message-ID: <[email protected]>
Subject: hello
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Any ideas what's going on here? Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 Rails 2.x 迁移后 -> 3.x 我遇到了同样的问题(尽管设置有点不同)。我的 html 电子邮件没有正文。我将我的邮件程序类从 models 文件夹移动到 mailers 文件夹中,并更改了我的视图文件名:
file_name.text.html.erb
=>
file_name.html.erb
我希望这有帮助。
After migration from Rails 2.x -> 3.x I had the same problem (a bit different setup though). My html emails had no body. I moved my mailer class from models folder into mailers folder and changed my view file names:
file_name.text.html.erb
=>
file_name.html.erb
I hope this helps.