Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>edit: Figured it out, the layouts follow a different naming scheme to the email templates. Just rename them as follows:</p> <pre><code>layout.text.html.erb =&gt; layout.html.erb layout.text.plain.erb =&gt; layout.text.erb </code></pre> <p>I also made the mistake of manually defining the parts, if you use this:</p> <pre><code>part :content_type =&gt; 'text/plain', :body =&gt; render_message('my_template') </code></pre> <p>Then Rails can't determine the content_type for your part and it assumes it's HTML.</p> <p>After I changed those two things it worked for me!</p> <p>original reply follows..</p> <hr> <p>I've struggled with this question many times in the past, usually ending up with some sort of non-dry quick and dirty solution. I always thought I was the only one with this problem because Google turns up exactly nothing useful on the subject.</p> <p>This time I decided to dig into Rails to figure it out but so far without much success, but maybe my findings will help someone else figure this out.</p> <p>What I found was that in ActionMailer::Base the #render_message method is tasked with determining the proper content_type and should assign it to @current_template_content_type. #default_template_format then either returns the proper mime type for the layout or, if @current_template_content_type isn't set, it will default to :html.</p> <p>This is what ActionMailer::Base#render_message looks like in my app (2.3.5)</p> <pre><code> def render_message(method_name, body) if method_name.respond_to?(:content_type) @current_template_content_type = method_name.content_type end render :file =&gt; method_name, :body =&gt; body ensure @current_template_content_type = nil end </code></pre> <p>The trouble is that method_name appears to be a string (the name of the local view, in my case "new_password.text.html") and strings of course do not respond_to #content_type, meaning @current_template_content_type will always remain nil, and so the #default_template_format will always default to :html.</p> <p>Not much closer to an actual solution, I know. The ActionMailer internals are just too opaque for me.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload