Trying to get past a mailer ActionView::MissingTemplate issue in Rails 6(.1.4.1). I have a rails project that invokes mailers from the command line. My minimal test case works fine on linux but fails on windows (there are mailers that run on both platforms). Here’s the test case.
app/mailers/emailer.rb:
class Emailer < ActionMailer::Base
default :from => "from@example.com"
def test_email
mail(
from: 'from@example.com',
to: 'to@somewhere.else.com',
subject: 'test email',
)
end
end
app/views/emailer/test_email.html.erb:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<h3>This is a test email</h3>
<p>Thanks for reading.</p>
</body>
</html>
and, test-email-bare.rb:
Emailer.test_email.deliver_now
If I invoke:
rails runner test-email-bare.rb
…on a linux deployment of the app, everything is fine, and the email gets delivered. But if I do the same thing on a windows deployment of the same code base, I get a the error:
C:/jeeves/Ruby/lib/ruby/gems/2.7.0/gems/actionmailer-6.1.3.2/lib/action_mailer/base.rb:967:in `each_template': Missing template emailer/test_email with "mailer". Searched in: (ActionView::MissingTemplate)
* "emailer"
procmon says that ruby does, in fact, find the template file (app/views/emailer/test_email.html.erb), so the actual problem may be elsewhere.
Some things I’ve searched for/tried already…
- Yes, I created the files in app/views/layouts/mailer.*
- Adding ‘layout “mailer”’ to the Emailer class
- Adding template_path and template_name to the mail() call in test_email
Anyone seen anything like this? Thanks much!