mjml-rails
mjml-rails copied to clipboard
unable to load included template when using MRML
I'm trying to use mjml-rails along with mrml and I'm not being able to make it work. I added the mrml gem as well as set use_mrml = true in the initializer. The issue is my template has Ruby code. If I remove the Ruby code, it works fine.
Steps to reproduce
Just try to render a template like:
# my_template.mjml
<mj-section>
<mj-column>
<mj-text>Hello user <%= @user.name %></mj-text>
</mj-column>
</mj-section>
The error is:
MRML::Error: unable to load included template
This WORKS with mjml, but not with mrml.
@lucasmello How is your controller setup? My controller/view works for both mjml and mrml:
def email
@issue = Issue.find(params[:issue_id])
respond_to do |format|
format.html { render :layout => 'email' }
format.text { render :layout => false }
format.mjml { render :layout => false }
end
end
@sighmon thanks for the reply, and sorry for the delay in replying back!
I'm using it on the notifier.rb:
def existing_user_invitation(user)
mail(
to: user.email,
from: "[email protected]",
subject: "Invitation to Join Account"
) do |format|
format.mjml
end
end
@lucasmello Would you mind creating a sample project showing your bug?
@lucasmello I happened to come across the same error in our codebase. I think ERB is getting skipped. If you rename my_template.mjml to my_template.mjml.erb it probably works.
I'm still having the same issue on 4.15.1.
If I name my file email.mjml and it contains ERB tags (<%= ... %>) then the template rendering will fail with:
MRML::Error: unable to load included template
Renaming the file email.mjml.erb gets rid of the error but then the MJML tags are ignored and I end up with this rendered instead of HTML:
<mjml>
<mj-head>
<mj-title>Mail title</mj-title>
<mj-attributes>
...
</mj-attributes>
</mj-head>
<mj-body>
...
</mj-body>
</mjml>
I was hoping using MRML could fix my troubles using MJML in production. I just can't get my capistrano deployment setup to find the MJML binary. It works locally, it works when I ssh into production and run it from console, but the rails server always fails with:
Couldn't find the MJML 4. binary.. have you run $ npm install mjml?
Ideas ?
Edit: Actually it works with Sidekiq, but when I try to deliver an email directly from the Rails app I keep getting the error :
Couldn't find the MJML 4. binary.. have you run $ npm install mjml?
Edit 2: Ok I got it fixed, I just needed to fully restart the Unicorn process instead of just killing it with USR2 for "zero-downtime" restart. The MRML issue still remains though, even if I don't really need it now that MJML is working.
@jerefrer Could you create a tiny sample app that reproduces the MRML bug?