所以我正在开发一个rails引擎并生成一个邮件,将我的观点放在
中app/
views/
my_engine/
user_mailer/
account_activation.html.erb
account_activation.text.erb
配置虚拟应用以显示我添加的预览
测试/虚设/配置/环境/ development.rb
config.action_mailer.preview_path = MSearcher::Engine.root.join('test/mailers')
测试/邮寄者/预览/ my_engine / user_mailer_preview.rb
module MyEngine
class UserMailerPreview < ActionMailer::Preview
def account_activation
User.first
UserMailer.account_activation(user)
end
end
end
现在,如果我创建我的邮件
/应用/邮寄者/ 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"
所以默认行为是在应该存在的文件夹上方查找我的模板。如何配置正确的行为?
答案 0 :(得分:1)
我最终做的是告诉它哪里可以找到布局
当我生成我的邮件时,它在
中创建了一个默认布局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不会自动执行此操作,但这解决了我的问题。