如何使用 Rails 在浏览器中查看电子邮件视图 [英] How to see e-mail views in browser using rails

查看:33
本文介绍了如何使用 Rails 在浏览器中查看电子邮件视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的 rails 应用程序处理电子邮件.现在,我知道查看电子邮件的唯一方法是将其发送给我自己.如何让views"文件夹下的notifications"文件夹中的daily_summary.html.haml"在浏览器中呈现?我在想我应该添加路线:

I am working on e-mails for my rails app. Right now the only way I know to view the e-mail is to send it to myself. How do I get "daily_summary.html.haml", which is in the "notifications" folder under the "views" folder, to render in the browser? I was thinking I should just add the route:

match 'notifications' => 'notifications/daily_summary'

但是我不知道如何处理控制器/动作方面的事情.

But then I don't know how to handle the controller/action side of things.

推荐答案

从 Rails 4.1 开始,电子邮件预览是原生的.您需要做的就是在此目录中创建一个类:

Since Rails 4.1, e-mail preview is native. All you need to do is create a class in this directory:

test/mailers/previews/

该类必须扩展 ActionMailer::Preview

class WeeklyReportPreview < ActionMailer::Preview
    def weekly_report
        WeeklyReport.weekly_report(User.first)
    end
end

编写返回Mail::Message 对象的方法.可以在开发环境中使用以下网址访问它们:

Write methods that return Mail::Message objects. They are accessible in the development environment using this url:

http://localhost:3000/rails/mailers/[preview_class_name]/[method_name]

就我而言:

http://localhost:3000/rails/mailers/weekly_report/weekly_report

更多信息可以在ActionMailer API 文档

这篇关于如何使用 Rails 在浏览器中查看电子邮件视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆