如何配置设备以使用自定义电子邮件布局?
当我说布局时,我指的不仅仅是视图,而是我生成的视图。在我自己的所有邮件程序上,我都使用默认布局。我在 SomeMailer.rb 文件中定义的
#some_mailer.rb
class SomeMailer < ActionMailer::Base
layout 'sometemplate'
是否有某种方法可以为 Devise Mailer 等执行此操作?
When I say layout I don't mean just simply the views, I generate those. On all my own mailers I'm using a default layout. Which I define in the SomeMailer.rb file
#some_mailer.rb
class SomeMailer < ActionMailer::Base
layout 'sometemplate'
Is there some way I can do this for the Devise Mailer et al.?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 Devise Github wiki 中找到了答案,
阅读会有所帮助。 ;-)
以下是 wiki 页面的参考:如何:创建自定义布局
Found the answer sitting in the Devise Github wiki,
Reading that helps. ;-)
Here is the reference of the wiki page: How To: Create custom layouts
devise.rb 中还有一个 parent_mailer 选项,假设您要在 devise 之外发送电子邮件,默认情况下此选项设置为 ActionMailer::Base< /strong>,但是如果您有一个已经从 ActionMailer::Base 继承的 ApplicationMailer,您可以将 parent_mailer 更改为此并获取所有内容您的布局和配置开箱即用。
无论如何,如果您不想更改设计邮件程序控制器中的任何内容,那么使用它来保持应用程序中布局的轨道流会更干净。
There is also a parent_mailer option in devise.rb, let's say you are sending emails outside of devise, by default this option is set to ActionMailer::Base, but if you have an ApplicationMailer that already is inheriting from ActionMailer::Base, you could change parent_mailer to this and get all your layouts and configurations out of the box.
In any case is a lot cleaner to use this to keep the rails flow of layouts in your applications if you don't want to change anything in the devise mailer controller.
确保在更改初始值设定项后重新启动 Rails 服务器。
Make sure to restart your rails server as you changed an initializer.
尝试重新打开 Devise::Mailer 类:
Try reopen Devise::Mailer class: