Ruby on Rails-Action邮件没有按照要求?

我有2个模型posend

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  "xyz@yahoo.co.in", :subject => " New purchase order send by " ) end end 

预期结果是邮件

在此处输入图像描述

如何从发送控制器将po的详细信息发送到邮件程序?

未测试的代码:用它作为参考。

 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

       

Dear <%= @po.vname %>

,

You have purchase order with invoice no <%= @po.invoiceno %>.

...... add your required information using @po object. .....

Thanks !

注意:这是一个示例代码,我无法在不通过应用程序的情况下给出确切的工作代码,但我确信这将帮助您更进一步。