Mailer question -- Order Confirmation

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

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)

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

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

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

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??

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

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

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

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

Thank you Fred. Works like a charm.

Elle