Question

I am new to action mailer. I have built an webpage in HAML which contains two tables. I want to embed them in my email body. So I have written the following code:

 class AlertsMailer < ActionMailer::Base
  default from: 'x@y.com'

  def mail_alert
    email_addresses = ['a@b.com', 'b@c.com']
    subject = "xyz"
    body = <Here I don't know what to write>
    logger.warn mail(:to => email_addresses, :subject => subject, :body =>body).deliver!  
  end
 end

So here how do I render the webpage in my mail or do I have to hardcode the table with its data in mail. But value embedded in the tables is supposed to change daily. So how do I implement it?

Was it helpful?

Solution

Have a read of this http://guides.rubyonrails.org/action_mailer_basics.html

You need to create a view for the mailer, this is where your content goes, this is all in section 2.1.3.

It also shows you how to create mailers in a slightly different (read better) fashion than your currently using.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top