我有2个模型po
和send
po:has_many发送
发送:belongs_to po
send
po
send_controller
class SendsController < ApplicationController
def new
@send = Send.new
end
def create
@send = Send.new(params[:send])
if @send.save
Pomailer.registration_confirmation(@send).deliver
flash[:success] = "Send mail"
redirect_to capax_path
else
flash[:warning] = "mail not send"
redirect_to capax_path
end
end
pomailer
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
预期结果为邮件
如何从发送控制器将po的详细信息发送到邮件程序?
答案 0 :(得分:1)
UNTESTED CODE:用它作为参考。
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
pomailer:
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
端
在视图中创建一个Pomailer文件夹并添加一个文件registration_confirmation.html.erb
<!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>
注意: 这是一个示例代码,我无法在不通过应用程序的情况下给出确切的工作代码,但我相信这会帮助您走得更远。