Forum: Ruby on Rails ActionMailer outside of Rails?

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.
Jason G. (Guest)
on 2007-05-13 06:22
Has anyone used ActionMailer outside of rails?  I have a requirement for
work that will not allow me to do this from within a rails app.  I have
successfully sent an email in the following manner:

MyMailer.deliver_clever_email(someArg,'testing!')

where the second argument is the body of the email, but when I try to
call just:

MyMailer.deliver_clever_email(someAr)

and use a template, it complains that it doesn't know where to find the
rhtml template.  How do I tell it where to look?  Any help would be
greatly appreciated!

-jay
Florian G. (Guest)
on 2007-05-13 06:35
ActionMailer has a configuration option called template_root.

http://api.rubyonrails.org/classes/ActionMailer/Base.html (see
Configuration)

This allows you to set the search path for templates. AFAIK, this is
really just the root, so it will look for
'#{TEMPLATE_ROOT}/my_mailer/clever_email.rhtml'.

Jason Guiditta wrote:
> Has anyone used ActionMailer outside of rails?  I have a requirement for
> work that will not allow me to do this from within a rails app.  I have
> successfully sent an email in the following manner:
>
> MyMailer.deliver_clever_email(someArg,'testing!')
>
> where the second argument is the body of the email, but when I try to
> call just:
>
> MyMailer.deliver_clever_email(someAr)
>
> and use a template, it complains that it doesn't know where to find the
> rhtml template.  How do I tell it where to look?  Any help would be
> greatly appreciated!
>
> -jay
Jason G. (Guest)
on 2007-05-14 03:17
Many thanks, Florian, that was exactly what I missed, works like a charm
now!  All I had to to was point it to the root view directory and it
figured the rest out on its own  :)

ActionMailer::Base.template_root = "views/"

-jay


Florian G. wrote:
> ActionMailer has a configuration option called template_root.
>
> http://api.rubyonrails.org/classes/ActionMailer/Base.html (see
> Configuration)
>
> This allows you to set the search path for templates. AFAIK, this is
> really just the root, so it will look for
> '#{TEMPLATE_ROOT}/my_mailer/clever_email.rhtml'.
This topic is locked and can not be replied to.