How can i send the details of the model object into the mailer from particular controller ?
I have 2 models
po: has_many sends
send: belongs_to po
Controller:
I have 2 models
po
and send.
Associations are as give below.
po: has_many sends
send: belongs_to po
Controller:
class SendsController < ApplicationController
def create
@send = Send.new(params[:send])
if @send.save
Pomailer.registration_confirmation(@send.po).deliver
flash[:success] = "Send mail"
redirect_to capax_path
else
flash[:warning] = "mail not send"
redirect_to capax_path
end
end
Mailer
class Pomailer < ActionMailer::Base
default from: "from@example.com" def registration_confirmation(po) @po = po mail(:to => "xyz@yahoo.co.in", :subject => " New purchase order send by " )
end
end
In views create a Pomailer folder and add a file registration_confirmation.html.erb
In Below code you can customize your E-mail template design.
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
</head>
<body>
<h1>Dear <%= @po.vname %></h1>,
<p>
You have purchase order with invoice no <%= @po.invoiceno %>.
</p>
<p>
......
add your required information using @po object.
.....
</p>
<p>Thanks !</p>
</body>
</html>
No comments:
Post a Comment