gpt4 book ai didi

ruby-on-rails - Rails Engine 邮件程序缺少模板

转载 作者:行者123 更新时间:2023-12-04 05:49:53 24 4
gpt4 key购买 nike

所以我正在开发一个 Rails 引擎并生成了一个邮件程序,其中包含我的观点

app/
views/
my_engine/
user_mailer/
account_activation.html.erb
account_activation.text.erb

配置虚拟应用程序以显示我添加的预览

test/dummy/config/environments/development.rb

config.action_mailer.preview_path = MSearcher::Engine.root.join('test/mailers')

test/mailers/previews/my_engine/user_mailer_preview.rb

module MyEngine
class UserMailerPreview < ActionMailer::Preview
def account_activation
User.first
UserMailer.account_activation(user)
end
end
end

现在如果我创建我的邮件程序

/app/mailers/my_engine/user_mailer

module MyEngine
class UserMailer < Application Mailer
def account_activation(user)
mail to: user.email, subject: "Account Activation"
end
end
end

有了这个我可以导航到 localhost:3000/rails/mailers/my_engine/users_mailer/account_activation

哪里出错了

Template is missing
Missing template layouts/mailer with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :coffee]}.
Searched in: *
"/home/me/workspace/rails/my_engine/test/dummy/app/views" *
"/home/me/workspace/rails/my_engine/app/views"

所以默认行为是在它应该位于的文件夹上方的文件夹中查找我的模板。如何配置正确的行为?

最佳答案

我最后做的是告诉它在哪里可以找到布局

当我生成我的邮件程序时,它在

中创建了一个默认布局
app/
views/
layouts
my_engine/
mailer.html.erb
mailer.text.erb
my_engine/
user_mailer/
account_activation.html.erb
account_activation.text.erb

但是 app/mailers/my_engine/application_mailer.rb 中的默认模板

module MyEngine
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
layout 'mailer'
end
end

这个布局确实应该是 'my_engine/mailer' 我不知道为什么 Rails 不自动执行此操作,但这解决了我的问题。

关于ruby-on-rails - Rails Engine 邮件程序缺少模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46478484/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com