Home ActionMailer Class not getting inherited in Rails App
Reply: 1

ActionMailer Class not getting inherited in Rails App

Wings2fly Published in 2018-02-09 15:14:42Z

I am working on a Ruby on Rails 4.2.10 App with no views of the project structure. It is the backend logic in a Microservices architecture.

The problem I have here is the ActionMailer class is not getting inherited by the subclasses.

The emails were sent previously. Now, this same implementation is not working. Does this have anything to do with the Rails version? Please help.


class ApplicationMailer < ActionMailer::Base
  default from: "from@example.com"
  layout 'mailer'


class SampleMailer < ApplicationMailer

    def  xlsx_email(email, xlsx, filename)
         mail.attachments[filename] = xlsx.read
         body = "The  report you requested is attached.\n\nThanks "
         mail(from: "noreply@sample.com", to: email, subject: "Report ", body: 


The error I get is

NameError: undefined local variable or method 'mail' for SampleMailer:Class

When I tried using the mail and attachment method to call directly using ActionMailer::Base , it showed error

ActionView::MissingTemplate: Missing template sample_mailer/xlsx_email with "mailer". Searched in:* "sample_mailer"

Arth Thakkar
Arth Thakkar Reply to 2018-02-09 15:37:15Z

If you do not provide a response format then your code will find for the template page to exist. "app/views/sample_mailer/xlsx_email.html.erb".

For the latter issue, you can try following if you don't want to render a template.

mail(from: "noreply@sample.com", to: email, subject: "Report ", body: 
      body) do |format|
    format.text { render plain: "Hello Mikel!" }

Check this link for more. https://apidock.com/rails/ActionMailer/Base/mail

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.30728 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO