2
votes

I am using Action Mailers on Rails. I followed the documentation but I can't get invitation_email.html.erb read properly by my browser. Here is the code on the invitation_email.html.erb:

<!DOCTYPE html>
<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />

    </head>
  <body>
    <h1><%= @sender.first_name %> vous invite à débattre.</h1>
      <p><%= @group_invitation.key %></p>
      <p> Cliquez ici : <%= link_to "Rejoindre", group_accept_invite_url(:key => @group_invitation.key) %>
      </p>
      <div class="button-test">
        button
      </div>
    </body>
</html>

Here is my code on the group_mailer.rb :

  class GroupMailer < ActionMailer::Base
  default from: 'Logora <[email protected]>'
  layout 'mailer'

  def invitation_email(group_invitation)
    @to = group_invitation.guest
    @sender = group_invitation.sender
    @subject = @sender.first_name + ' vous invite à débattre sur Logora'
    @group_invitation = group_invitation
    m = mail(to: @to, subject: @subject, content_type: "text/html")
  end

end

And finally, here is the message I have when I send an email to myself :

Logora 21:29 (Il y a 7 minutes) À moi

----==_mimepart_5c32651265cd8_16f563ff3a1d01db04642e Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable test vous invite =C3=A0 d=C3=A9battre. uh9sNDoDQbYU7ZYixKZHCCjG

Cliquez ici : Rejoindre

button ----==_mimepart_5c32651265cd8_16f563ff3a1d01db04642e Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable test vous invite =C3=A0 d=C3=A9battre. Cliquez ici : Rejoindre ----==_mimepart_5c32651265cd8_16f563ff3a1d01db04642e--

Any help would be much appreciated !

2

2 Answers

2
votes

As stated in the documentation passing :content_type also expects that :body will be passed (which will skip the template rendering step). So to have the template rendered correctly I suspect you need to remove content_type: "text/html":

mail(to: @to, subject: @subject)
1
votes

content="text/html; charset=UTF-8" typo, missing some double quotes. :)