# Mailer question -- Order Confirmation

**URL:** <https://www.ruby-forum.com/t/mailer-question-order-confirmation/122173>\
**Category:** Rails\
**Created:** [December 5, 2007, 6:27am UTC](https://www.ruby-forum.com/t/mailer-question-order-confirmation/122173 "2007-12-05T06:27:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![elle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ccd318/32.png) [@elle](https://www.ruby-forum.com/u/elle)\
**Post date:** [December 5, 2007, 6:27am UTC](https://www.ruby-forum.com/t/mailer-question-order-confirmation/122173/1 "2007-12-05T06:27:12Z")

</div>

Hi,

I have a method “process” to process an order. It works good. I then  
added an actionmailer to send an email confirmation when the order is  
processed. I believed I followed the example from AWDWR 2nd ed.  
Anyhow, I how get an error in regards to this addition:

NameError (undefined local variable or method `order' for #<Order: 0x34fbcdc>): /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ active_record/base.rb:1860:in`method\_missing’  
.//app/models/order.rb:38:in `process' .//app/controllers/cart_controller.rb:103:in`place\_order’

My order.rb model line 38 says:  
OrderMailer.confirm(order)

My order)mailer.rb has:  
def confirm(order)  
@subject = ‘Company Order Confirmation’  
@body[“order”] = order  
@recipients = order.email  
@bcc = ‘orders@…’  
@from = ‘orders@…’  
@sent\_on = Time.now  
@headers[“Organization”] = “Company”  
end

Would anyone know what the problem is?

TIA,  
Elle

---

<div class="post-metadata">

**Author:** ![elle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ccd318/32.png) [@elle](https://www.ruby-forum.com/u/elle)\
**Post date:** [December 5, 2007, 8:41am UTC](https://www.ruby-forum.com/t/mailer-question-order-confirmation/122173/2 "2007-12-05T08:41:41Z")

</div>

On 5 Dec 2007, at 05:26, elle wrote:

> /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/  
> active\_record/base.rb:1860:in `method_missing' .//app/models/order.rb:38:in`process’  
> .//app/controllers/cart\_controller.rb:103:in `place\_order’
> 
> My order.rb model line 38 says:  
> OrderMailer.confirm(order)

The error message suggests that you are calling  
OrderMailer.confirm(order) from an instance of order. Assuming that it  
is trying to send the confirmation email for itself, that should  
probably be  
OrderMailer.confirm(self)

Fred

---

<div class="post-metadata">

**Author:** ![elle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ccd318/32.png) [@elle](https://www.ruby-forum.com/u/elle)\
**Post date:** [December 5, 2007, 10:20am UTC](https://www.ruby-forum.com/t/mailer-question-order-confirmation/122173/3 "2007-12-05T10:20:04Z")

</div>

What you say sounds very logical but I still get an error.

My process method in the order.rb model says:  
35 def process  
36 result = true  
37 …  
38 OrderMailer.confirm(self)  
39 self.status = ‘processed’  
40 save!  
41 result  
42 end

The place\_order method in the cart\_controller.rb:  
94 def place\_order  
95 @page\_title = “Checkout”  
96 @order = Order.new(params[:order])  
97 @order.customer\_ip = request.remote\_ip  
98 @order.customer\_id = @customer.id  
99 @order.discount = @customer.discount  
100 populate\_order  
101  
102 if @order.save  
103 if @order.process  
104 flash[:notice] = ‘Your order has been submitted, and will be  
processed immediately.’  
105 session[:order\_id] = @order.id  
106 # Empty the cart  
107 @cart.cart\_items.destroy\_all  
108 redirect\_to :action =\> ‘thank\_you’  
109 else  
110 flash[:notice] = “Error while placing order.  
‘#{@order.error\_message}’”  
111 render :action =\> ‘view\_cart’  
112 end  
113 else  
114 render :action =\> ‘checkout’  
115 end  
116 end

And the error message is:  
NoMethodError in CartController#place\_order  
undefined method `confirm' for OrderMailer:Class /usr/local/lib/ruby/gems/1.8/gems/actionmailer-1.3.3/lib/action_mailer/ base.rb:335:in `method\_missing’  
app/models/order.rb:38:in `process' app/controllers/cart_controller.rb:103:in `place\_order’

Any ideas??

Thanks  
Elle

On Dec 5, 6:40 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![elle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ccd318/32.png) [@elle](https://www.ruby-forum.com/u/elle)\
**Post date:** [December 7, 2007, 8:01am UTC](https://www.ruby-forum.com/t/mailer-question-order-confirmation/122173/4 "2007-12-07T08:01:57Z")

</div>

Thanks Fred. I originally had it as:  
OrderMailer.create\_confirm(order)  
and it gave me an error of undefined method. Once I changed it to  
self, no more problems.

Cheers,  
Elle

On Dec 5, 8:43 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![elle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ccd318/32.png) [@elle](https://www.ruby-forum.com/u/elle)\
**Post date:** [December 5, 2007, 10:44am UTC](https://www.ruby-forum.com/t/mailer-question-order-confirmation/122173/5 "2007-12-05T10:44:05Z")

</div>

On 5 Dec 2007, at 09:19, elle wrote:

> app/controllers/cart\_controller.rb:103:in `place\_order’
> 
> Any ideas??

That was me being half awake. If you checkAWDR, you’ll see that you  
either need to do  
OrderMailer.create\_confirm(self) to create an email (but not send it)  
or  
OrderMailer.deliver\_confirm(self) to create and send an email

Fred

---

<div class="post-metadata">

**Author:** ![elle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ccd318/32.png) [@elle](https://www.ruby-forum.com/u/elle)\
**Post date:** [December 7, 2007, 10:17am UTC](https://www.ruby-forum.com/t/mailer-question-order-confirmation/122173/6 "2007-12-07T10:17:46Z")

</div>

I still have another question. So, now I don’t get an error but I also  
don’t get an email for order confirmation.  
…but… I do get an email when a user fills out a contact form. Any  
ideas why the email is not getting sent?

I’m not even sure what code to send to check where the problem is.

Elle

---

<div class="post-metadata">

**Author:** ![elle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ccd318/32.png) [@elle](https://www.ruby-forum.com/u/elle)\
**Post date:** [December 12, 2007, 5:28am UTC](https://www.ruby-forum.com/t/mailer-question-order-confirmation/122173/7 "2007-12-12T05:28:44Z")

</div>

Thank you Fred. Works like a charm.

Elle

On Dec 7, 8:35 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![elle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ccd318/32.png) [@elle](https://www.ruby-forum.com/u/elle)\
**Post date:** [December 7, 2007, 10:35am UTC](https://www.ruby-forum.com/t/mailer-question-order-confirmation/122173/8 "2007-12-07T10:35:58Z")

</div>

On 7 Dec 2007, at 09:17, elle wrote:

> I still have another question. So, now I don’t get an error but I also  
> don’t get an email for order confirmation.  
> …but… I do get an email when a user fills out a contact form. Any  
> ideas why the email is not getting sent?
> 
> I’m not even sure what code to send to check where the problem is.

create\_confirm doesn’t send email: it creates a TMail::Mail object  
which you can then send. If you just want to send the email you should  
use deliver\_confirm instead of create\_confirm

Fred
