Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails mailer and mailer views in subfolder not working

I have a mailer that I can see in my log is getting sent, but the email body does not contain anything from the mailer view.

It's due to the fact that I've put things in subfolders and i've tried using :template_path in my mail function but to no avail.

app/mailers/marketing/marketing_mailer.rb

class Marketing::MarketingMailer < ActionMailer::Base

    require 'mail'
    address = Mail::Address.new "[email protected]" # ex: "[email protected]"
    address.display_name = "Text" # ex: "John Doe"
    # Set the From or Reply-To header to the following:
    address.format # returns "John Doe <[email protected]>"
    default from: address

    # Sends an email when someone fills out the contact form
    def contact(name, email, message)
        @name = name
        @email = email
        @message = message
        mail(:subject => "Test", :to => '[email protected]', :reply_to => @email) # <== I've tried using :template_path => 'marketing', 'marketing/marketing_mailer', etc, but none worked.
    end
end

/app/views/marketing/marketing_mailer/contact.html.erb

<!DOCTYPE html>
<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
  </head>
  <body>
    <p>Name: <%= @name %></p>
    <p>Email: <%= @email %></p>
    <p>Message: <%= @message %></p>
  </body>
</html>

I noticed that devise has mailer views inside /views/devise/mailers/... so I know it's possible, but i'm not sure how.

like image 404
Catfish Avatar asked Dec 03 '13 05:12

Catfish


2 Answers

Have you tried mail with {:template_path => 'marketing/marketing_mailer, :template_name =>'contact'} ?

The template name probably expects the namespace in the filename somehow

like image 109
journeyer Avatar answered Sep 24 '22 17:09

journeyer


Does it work without the template Rendering

   class Marketing::MarketingMailer < ActionMailer::Base
   def welcome_email(user, email_body)
     mail(to: user.email,
     body: email_body,
     content_type: "text/html",
     subject: "Already rendered!")
   end
   end
like image 26
nil Avatar answered Sep 22 '22 17:09

nil