# How to modify the template path for ActionMailer used in a Ruby script

**URL:** <https://www.ruby-forum.com/t/how-to-modify-the-template-path-for-actionmailer-used-in-a-ruby-script/204082>\
**Category:** Rails\
**Created:** [March 4, 2011, 4:34pm UTC](https://www.ruby-forum.com/t/how-to-modify-the-template-path-for-actionmailer-used-in-a-ruby-script/204082 "2011-03-04T16:34:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [March 4, 2011, 4:34pm UTC](https://www.ruby-forum.com/t/how-to-modify-the-template-path-for-actionmailer-used-in-a-ruby-script/204082/1 "2011-03-04T16:34:51Z")

</div>

SOLVED] posted initially as a question

I am testing a ruby 1.9.2 script (it’ll be run in a cron task  
later…) in which I am trying to use ActionMailer  
All my files are in a single folder 'joinus\_email

- joinus\_email  
joinus\_email.rb  
notifier.rb
  - notifications  
joinus\_email.html.erb  
joinus\_email.text.erb

running the script joinus\_email.rb, (in which I defined the  
ActionMailer::Base.smtp\_settings)  
mail = Notifier.joinus\_email(“removed\_email\_address@domain.invalid”).deliver

is raising an exception :  
exception: Missing template notifier/joinus\_email with  
{:handlers=\>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=\>[:html],  
:locale=\>[:en]}  
in view paths

notifier.rb  
class Notifier \< ActionMailer::Base  
default :from =\> “removed\_email\_address@domain.invalid”  
def joinus\_email(destination, coupon)  
@url = “[http://example.com](http://example.com)”  
mail(:template\_path =\> ‘notifications’, :to =\>  
destination, :subject =\> “Welcome”) do |format|  
format.html  
format.text  
end  
end  
end

there was something wrong with the :template\_path =\>  
‘notifications’ parameter…  
I tried a relative path : " ./notifications" same error raised  
I also tried to define upon initialization : TEMPLATE\_ROOT = “./  
notifications” in the joinus\_email.rb script , same error raised …

I found a trick :

ActionMailer::Base.prepend\_view\_path(‘/my/other/path/to/search/first/’)

so in my case , I renamed the notifications folder to notifications  
and I wrote :

ActionMailer::Base.prepend\_view\_path(‘./’)

et voilà … hope it’ll help someone…

---

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [March 4, 2011, 4:59pm UTC](https://www.ruby-forum.com/t/how-to-modify-the-template-path-for-actionmailer-used-in-a-ruby-script/204082/2 "2011-03-04T16:59:07Z")

</div>

[SOLVED] using ActionMailer::Base.prepend\_view\_path(’./’) and  
changing the notifications folder name to notifier
