Forum: Ruby on Rails Question on Active Mailer

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ror D. (Guest)
on 2006-04-21 11:01
Hi
I want to create send emails to users as soon as a product is created;

So I created scaffold for Product and before as soon as I do the save I
call my send_email method in another controller; Now I want to pass on
the Product record we created. I tried sending the product as @product,
:product,etc. (tried all) and none work; my idea is to get the product
record and put it in the email template like:-

"Dear Customer. <%= product.name %> has arrived at our warehouse and
ready for pick up....."

thanks
Bryan D. (Guest)
on 2006-04-21 18:34
ror directory wrote:
> Hi
> I want to create send emails to users as soon as a product is created;
>
> So I created scaffold for Product and before as soon as I do the save I
> call my send_email method in another controller; Now I want to pass on
> the Product record we created. I tried sending the product as @product,
> :product,etc. (tried all) and none work; my idea is to get the product
> record and put it in the email template like:-
>
> "Dear Customer. <%= product.name %> has arrived at our warehouse and
> ready for pick up....."
>
> thanks

In your send_mail method in whatever your mailer model is, you need to
change the definition of

send_mail(sent_at = Time.now)

to

send_mail(product, sent_at = Time.now)

and then in the body of that method,

@body = {:product => product}

That will get you @product in the .rhtml file for send_mail.
This topic is locked and can not be replied to.