如何配置设备以使用自定义电子邮件布局?

发布于 2024-10-17 16:27:41 字数 226 浏览 1 评论 0原文

当我说布局时,我指的不仅仅是视图,而是我生成的视图。在我自己的所有邮件程序上,我都使用默认布局。我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

£噩梦荏苒 2024-10-24 16:27:41

在 Devise Github wiki 中找到了答案,

阅读会有所帮助。 ;-)

config.to_prepare do
  Devise::Mailer.layout "simple" # simple.haml or simple.erb
  Devise::Mailer.helper :mailer
end

以下是 wiki 页面的参考:如何:创建自定义布局

Found the answer sitting in the Devise Github wiki,

Reading that helps. ;-)

config.to_prepare do
  Devise::Mailer.layout "simple" # simple.haml or simple.erb
  Devise::Mailer.helper :mailer
end

Here is the reference of the wiki page: How To: Create custom layouts

咽泪装欢 2024-10-24 16:27:41

devise.rb 中还有一个 parent_mailer 选项,假设您要在 devise 之外发送电子邮件,默认情况下此选项设置为 ActionMailer::Base< /strong>,但是如果您有一个已经从 ActionMailer::Base 继承的 ApplicationMailer,您可以将 parent_mailer 更改为此并获取所有内容您的布局配置开箱即用。

无论如何,如果您不想更改设计邮件程序控制器中的任何内容,那么使用它来保持应用程序中布局的轨道流会更干净。

# devise.rb
config.parent_mailer = 'ApplicationMailer'

# application_mailer.rb
class ApplicationMailer < ActionMailer::Base
    layout 'mailer'
end

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.

# devise.rb
config.parent_mailer = 'ApplicationMailer'

# application_mailer.rb
class ApplicationMailer < ActionMailer::Base
    layout 'mailer'
end
万人眼中万个我 2024-10-24 16:27:41
# Devise::Mailer inherits from ActionMailer::Base other mail will work fine.

## app/mailers/deviser_mailer.rb

class DeviseMailer < Devise::Mailer
  layout 'email'
  default from: I18n.t("mailer.default.from")
end

## then in config/initializer/devise.rb

# Configure the class responsible to send e-mails.
config.mailer = "DeviseMailer"

确保在更改初始值设定项后重新启动 Rails 服务器。

# Devise::Mailer inherits from ActionMailer::Base other mail will work fine.

## app/mailers/deviser_mailer.rb

class DeviseMailer < Devise::Mailer
  layout 'email'
  default from: I18n.t("mailer.default.from")
end

## then in config/initializer/devise.rb

# Configure the class responsible to send e-mails.
config.mailer = "DeviseMailer"

Make sure to restart your rails server as you changed an initializer.

眼眸里的快感 2024-10-24 16:27:41

尝试重新打开 Devise::Mailer 类:

 class Devise::Mailer < ActionMailer::Base
   layout 'sometemplate'
 end

Try reopen Devise::Mailer class:

 class Devise::Mailer < ActionMailer::Base
   layout 'sometemplate'
 end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文