Closed dyanagi closed 4 years ago
@dyanagi Sorry for the delay in getting back to you. I've had a play with your repo and forked it with some other options for setting up the user mailer: https://github.com/sighmon/example_mjml_rails/commit/a22b184c0b2e0c2eaf7a87cf35a3ded82da2f011
How does that look to you?
@sighmon Thank you! I appreciate it. I understand the main cause of this issue.
The code below didn't compile MJML tags because mailer.html.erb
took the priority to be the default layout for the UserMailer. ( mailer.html.mjml
wasn't used. )
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
layout 'mailer'
end
class UserMailer < ApplicationMailer
def user_signup_confirmation
@greeting = "Hi"
mail to: "to@example.org" do |format|
format.text
format.html # looks for "mailer.html.erb" and then "mailer.html.mjml"
end
end
I removed mailer.html.erb
and now MJML tags are compiled.
Could you take a look at this pull request to see if the changes look good? https://github.com/dyanagi/example_mjml_rails/pull/1
Also, maybe we could mention this behaviour in the documentation. https://github.com/sighmon/mjml-rails#using-email-layouts
Thanks!
@dyanagi That looks great to me. Would you like to put in a PR with the changes to the documentation you'd like with a link to your example repo?
@sighmon Thanks! Sure, I'll work on it!
@sighmon Thanks for reviewing and merging it, Simon! I'm closing this issue.
Hi, thank you for creating this great gem!
I faced an issue with using default layouts while using this gem in Rails 6.0.0.
I followed this section with Rails 6, but my MJML tags weren't compiled into HTML.
https://github.com/sighmon/mjml-rails#using-email-layouts
Screenshot:
My workaround is to change
to
and change the filename
user_signup_confirmation.html.erb
touser_signup_confirmation.mjml.erb
Now, it works as expected with the layout.
I created a sample application with
mjml-rails
in Rails 6 (with no database, to make it easier to setup), which is currently working with the workaround.https://github.com/dyanagi/example_mjml_rails
The Git commit to creating this sample:
https://github.com/dyanagi/example_mjml_rails/commit/b30ac7c2c540e5894380694eed8aa2a68051f390
Notes:
mailer.html.mjml
was generated automatically byrails g mailer foobar
command