Forum: Ruby on Rails How to modify the template path for ActionMailer used in a Ruby script

Ee0293412faca21e4ebf3326ed9d5f8c?d=identicon&s=25 Kad Kerforn (kadoudal)
on 2011-03-04 16:34
(Received via mailing list)
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("john.doe@acme.com").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 => "system@example.com"
    def joinus_email(destination, coupon)
      @url  = "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....
Ee0293412faca21e4ebf3326ed9d5f8c?d=identicon&s=25 Kad Kerforn (kadoudal)
on 2011-03-04 16:59
(Received via mailing list)
[SOLVED]  using ActionMailer::Base.prepend_view_path('./')   and
changing the notifications folder name to notifier
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.