Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible bug with partials in email templates #2231

Open
CyberFerret opened this issue Sep 29, 2020 · 1 comment
Open

Possible bug with partials in email templates #2231

CyberFerret opened this issue Sep 29, 2020 · 1 comment

Comments

@CyberFerret
Copy link
Contributor

In Padrino 0.14.4 running on Ruby 2.5, I am using partial to add HAML snippets into emails I am sending out using Mailer.

Folder structure is as follows:

/app
  |
   - views
      |
       - mailers
          |
           - worker_mailer
              |
               - layouts
                   |
                    - email_layout.haml
              |
               - my_email.haml
               - _snippet1.haml
               - _snippet2.haml

So I set up within worker_mailer.rb:

email :my_email do |recipient, sender, company|
  from          "me@mycompany.com"
  to            recipient
  reply_to      sender
  subject       'This is my subject line!'
  content_type  'text/html'
  via           :smtp
  render        :my_email, :layout => 'email_layout', :locals => {:company => ...etc... }
end

(Side note: Wish we could use the locals declaration within the email block, but it looks like if we are rendering using templates, we have to move the locals to a parameter within the render line?!)

Then in the my_email.haml template, I have partials within the document like so:

%p Blah...
%div
  =partial 'snippet1', :engine => :haml, :locals => {...}
  %span Blah...
  =partial 'snippet2', :engine => :haml, :locals => {...}

However when trying to send the email, I am getting the error:

Errno::ENOENT: No such file or directory @ rb_sysopen - /<redacted>/myapp/app/views/mailers/worker_mailer/worker_mailer/_snippet1.haml

(Note the duplicated 'worker_mailer' folder in the error message).

If I then try and create a subfolder called 'worker_mailer' under the existing 'worker_mailer' folder and put _snippet1.haml in there, then the first line will pass OK, but it throws an error on the next partial with:

Errno::ENOENT: No such file or directory @ rb_sysopen - /<redacted>/myapp/app/views/mailers/worker_mailer/worker_mailer/worker_mailer/_snippet2.haml

(Note that the 'worker_mailer' folder appears to be recursively adding to itself for each partial in the template!)

I've tried hard coding the path to the partial template, but with no success. The rendering routine seems to want to keep adding another 'worker_mailer' to the parent folder for each subsequent partial. i.e.:

  =partial '/worker_mailer/snippet1', :engine => :haml, :locals => {...}

still doesn't work.

Is this a bug in rendering.rb or am I doing something wrong?

@nesquena
Copy link
Member

nesquena commented Oct 3, 2020

Sorry to hear about this issue. Unfortunately I don't think we had tested partials in email templates much, or at least I don't recall testing that very much. I could see this being a fairly easy fix. Would be happy to merge in a fix if someone sees this and decides to take a crack at it and open a PR.

CyberFerret added a commit to CyberFerret/padrino-framework that referenced this issue Oct 11, 2020
… partials in email templates

As per padrino#2231, when using multiple partials within an email template, the mailer name keeps getting added to the file path for each subsequent partial in the same template, resulting in an `Errno::ENOENT: No such file or directory @ rb_sysopen` error.

Added a check to `settings.view` in the render routine to see if the mailer path was already in the string before adding it.
maysam pushed a commit to HR-Partner/padrino-framework that referenced this issue Jul 24, 2021
… partials in email templates

As per padrino#2231, when using multiple partials within an email template, the mailer name keeps getting added to the file path for each subsequent partial in the same template, resulting in an `Errno::ENOENT: No such file or directory @ rb_sysopen` error.

Added a check to `settings.view` in the render routine to see if the mailer path was already in the string before adding it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants