[英]ActionView is missing template in Preview. How to resolve?
我目前正在嘗試讓 ActionMailer 發送帶有 Letter_Opener gem 的 email。 當我嘗試使用localhost:3000/mailer/order_mailer
查看預覽時,終端會記錄此錯誤:
app/mailers/order_mailer.rb:10:in `new_order_email'
Started GET "/rails/mailers/order_mailer/new_order_email" for ::1 at 2023-01-27 16:27:38 -0800
Processing by Rails::MailersController#preview as HTML
Parameters: {"path"=>"order_mailer/new_order_email"}
OrderMailer#new_order_email: processed outbound mail in 1.2ms
Completed 500 Internal Server Error in 24ms (Allocations: 9119)
ActionView::MissingTemplate (Missing template order_mailer/new_order_email with "mailer".
Searched in:
* "order_mailer"
):
應用程序/郵件程序/order_mailer.rb :
class OrderMailer < ApplicationMailer
default from: 'actionMailerTester2301@gmail.com'
# layout "order_mailer"
def new_order_email
@email = 'joeDANE@example.com'
mail(to: @email, subject: "Thank you for your donation.")
end
end
在瀏覽器上,指出了mail(to:.....
行。我查看了多個 stackoverflow 條目,但我無法弄清楚,盡管我將其歸因於我對 Ruby 的不熟悉,而不是關於了解問題。
我希望如果我能弄清楚為什么預覽不起作用,我就能找出 Letter Opener gem 的次要問題。
Ruby on Rails 更喜歡遵循某些約定而不是配置。 在大多數情況下,只遵循 Rails 的方式而不是過度定制您的應用程序會更容易和直接。
在這個具體示例中,我建議不要更改或重新配置 Rails 查找郵件程序視圖的位置,而只是將視圖放在默認文件夾中。
按照約定,對於郵件程序視圖以及您的郵件程序及其方法的命名方式,視圖應該像這樣命名並位於app/views
文件夾中(而不是在app/mailers/views
中):
app/views/order_mailer/new_order_email.html.erb
app/views/order_mailer/new_order_email.text.erb
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.