Rails 6.0.2 ActionMailer 问题:找不到模板 [英] Rails 6.0.2 ActionMailer Issue: Template not found
问题描述
我在开发环境中.在 UI 中触发电子邮件时,我在浏览器中收到错误消息:
没有交互式请求的模板Admins::AdminsController#testmail 缺少请求格式的模板:text/html笔记!除非另有说明,Rails 需要一个动作来渲染同名的模板,包含在以其控制器命名的文件夹中.如果此控制器是响应 204(无内容)的 API,不需要模板,那么在尝试通过浏览器访问时会出现此错误,因为我们希望为此类请求呈现 HTML 模板.如果是这样,请继续.
<块引用>
日志显示:
在 2020-03-05 08:28:00 +0100 开始 GET "/en/admins/1/testmail" for 127.0.0.1由 Admins::AdminsController#testmail 处理为 HTML参数:{"locale"=>"en", "admin_id"=>"1"}在 layouts/mailer 中渲染 test_mailer/testmail.text.erb在 layouts/mailer 中渲染 test_mailer/testmail.text.erb(持续时间:0.1 毫秒 | 分配:4)TestMailer#testmail:在 2.0 毫秒内处理出站邮件已投递邮件 5e60aa00a74a7_20213ffce2ad423c8083a@domain.example.com.mail (59.0ms)日期:2020 年 3 月 5 日星期四 08:28:00 +0100来自:admin@domain.com至:me@example.com邮件 ID:<5e60aa00a74a7_20213ffce2ad423c8083a@domain.example.com.mail.mail>主题:欢迎来到我的真棒网站Mime 版本:1.0内容类型:文本/纯文本;字符集=UTF-8内容传输编码:7 位欢迎来到example.com================================================您已成功注册 example.com,您的用户名是:XXXX要登录该网站,只需点击以下链接: .感谢您的加入,祝您有美好的一天!完成 406 Not Acceptable in 64ms (ActiveRecord: 0.0ms | Allocations: 3862)ActionController::MissingExactTemplate(Admins::AdminsController#testmail 缺少请求格式的模板:text/html):actionpack (6.0.2.1) lib/action_controller/metal/implicit_render.rb:45:in `default_render'actionpack (6.0.2.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `block in send_action'actionpack (6.0.2.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `tap'actionpack (6.0.2.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'actionpack (6.0.2.1) lib/abstract_controller/base.rb:196:in `process_action'
从上面可以看到,模板在错误发生之前就被渲染了.
<块引用>我的邮件程序类:
class TestMailer <应用程序邮件程序定义测试邮件邮件(至:'user@domain.com',主题:'欢迎来到我的真棒网站') do |format|格式文本结尾结尾结尾
当然模板放在/app/views/test_mailer/testmail.text.erb
.
我在 development.rb 中的邮件服务器配置是
我在本地主机上运行 mailcatcher
config.action_mailer.raise_delivery_errors = trueconfig.action_mailer.perform_caching = falseconfig.action_mailer.smtp_settings = {地址:'本地主机',端口:1025}config.action_mailer.delivery_method :smtpconfig.action_mailer.perform_deliveries = trueconfig.action_mailer.raise_delivery_errors = false
我在 Centos 7 上,整个 Rails 应用程序路径中没有特殊字符或空格感谢您的调查.
问题不是根据日志发送成功的邮件
问题是你的控制器操作 Admins::AdminsController#testmail
视图中没有模板来在成功发送电子邮件时呈现任何 html
我想路径应该是这样的:
/app/views/admins/admins/testmail.html.erb
I'm in the development environment. When triggering an email in the UI, I get the error in the browser:
No template for interactive request
Admins::AdminsController#testmail is missing a template for request formats: text/html
NOTE!
Unless told otherwise, Rails expects an action to render a template with the same name,
contained in a folder named after its controller. If this controller is an API responding with 204 (No Content),
which does not require a template, then this error will occur when trying to access it via browser,
since we expect an HTML template to be rendered for such requests. If that's the case, carry on.
The log shows:
Started GET "/en/admins/1/testmail" for 127.0.0.1 at 2020-03-05 08:28:00 +0100
Processing by Admins::AdminsController#testmail as HTML
Parameters: {"locale"=>"en", "admin_id"=>"1"}
Rendering test_mailer/testmail.text.erb within layouts/mailer
Rendered test_mailer/testmail.text.erb within layouts/mailer (Duration: 0.1ms | Allocations: 4)
TestMailer#testmail: processed outbound mail in 2.0ms
Delivered mail 5e60aa00a74a7_20213ffce2ad423c8083a@domain.example.com.mail (59.0ms)
Date: Thu, 05 Mar 2020 08:28:00 +0100
From: admin@domain.com
To: me@example.com
Message-ID: <5e60aa00a74a7_20213ffce2ad423c8083a@domain.example.com.mail.mail>
Subject: Welcome to My Awesome Site
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Welcome to example.com
===============================================
You have successfully signed up to example.com,
your username is: XXXX
To login to the site, just follow this link: .
Thanks for joining and have a great day!
Completed 406 Not Acceptable in 64ms (ActiveRecord: 0.0ms | Allocations: 3862)
ActionController::MissingExactTemplate (Admins::AdminsController#testmail is missing a template for request formats: text/html):
actionpack (6.0.2.1) lib/action_controller/metal/implicit_render.rb:45:in `default_render'
actionpack (6.0.2.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `block in send_action'
actionpack (6.0.2.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `tap'
actionpack (6.0.2.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (6.0.2.1) lib/abstract_controller/base.rb:196:in `process_action'
One can see above that the template is rendered before the error occurs.
My Mailer class:
class TestMailer < ApplicationMailer
def testmail
mail(to: 'user@domain.com',
subject: 'Welcome to My Awesome Site') do |format|
format.text
end
end
end
Of course the template is placed in /app/views/test_mailer/testmail.text.erb
.
My mail server config in development.rb is
I have mailcatcher running on localhost
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_caching = false
config.action_mailer.smtp_settings = {
address: 'localhost',
port: 1025
}
config.action_mailer.delivery_method :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
I'm on a Centos 7, no special characters nor whitespaces in the whole Rails app path Thanks for your investigations.
the problem is not the email that is sent successfully according to the log
the problem is you controller action Admins::AdminsController#testmail
doesn´t have a template in the views to render whatever html when a email is successfully sent
I suppose the path would be something like this:
/app/views/admins/admins/testmail.html.erb
这篇关于Rails 6.0.2 ActionMailer 问题:找不到模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!