Question

i have 2 models po and send

po: has_many sends

send: belongs_to po

send

send table

po

po table

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

Expected outcome to be mail

enter image description here

How can i send the details of the po into the mailer from send controller ?

Was it helpful?

Solution

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

end

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.

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