Ruby on Rails-Action邮件程序没有按需要? [英] Ruby on Rails-Action mailer no as per desired?
本文介绍了Ruby on Rails-Action邮件程序没有按需要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有2个模型 po
和发送
po:has_many发送
发送:belongs_to po
发送
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
预期的邮件结果
推荐答案
未定义的代码如何将邮件的详细信息发送到发送控制器的邮件程序? :用它作为参考。
UNTESTED CODE: use it as a reference.
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
In views create a Pomailer folder and add a file 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>
注意:
这是一个示例代码,我无法给你准确的工作代码没有但是我相信这将有助于你走得更远。
NOTE: This is a sample code ,, i cannot give u exact working code without going throught application,,But i am sure this will help you to go farther.
这篇关于Ruby on Rails-Action邮件程序没有按需要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文