ActionMailer Outside Rails

Hi everyone,

Has anybody used ActionMailer outside rails? I have googled and found some things, but I can not seem to get it to work for a stand-alone app.

The problem is setting the template_root. If I dont' set it, ActionMailer can not find my mail templates. If I try and set it, I get an uninitialized constant ActionView::Base::ActionController when I:

ActionMailer::Base.template_root = 'some-path'

I'm putting action_mailer, action_pack, rack, and active_support in a vendor subdir of the app, so I can ship it with the app and adding to the LOAD_PATH at the beggining og the app.

Appreciate any help here!!!!!!

Here is the full error:

/home/gditric/sandbox/ffl/vendor/activesupport-2.3.4/lib/ active_support/dependencies.rb:105:in `rescue in const_missing': uninitialized constant ActionView::Base::ActionController (NameError)         from /home/gditric/sandbox/ffl/vendor/activesupport-2.3.4/lib/ active_support/dependencies.rb:94:in `const_missing'         from /home/gditric/sandbox/ffl/vendor/actionpack-2.3.4/lib/ action_view/base.rb:191:in `cache_template_loading?'         from /home/gditric/sandbox/ffl/vendor/actionpack-2.3.4/lib/ action_view/paths.rb:5:in `type_cast'         from /home/gditric/sandbox/ffl/vendor/actionpack-2.3.4/lib/ action_view/paths.rb:16:in `block in initialize'         from /home/gditric/sandbox/ffl/vendor/actionpack-2.3.4/lib/ action_view/paths.rb:16:in `map!'         from /home/gditric/sandbox/ffl/vendor/actionpack-2.3.4/lib/ action_view/paths.rb:16:in `initialize'         from /home/gditric/sandbox/ffl/vendor/actionpack-2.3.4/lib/ action_view/base.rb:205:in `new'         from /home/gditric/sandbox/ffl/vendor/actionpack-2.3.4/lib/ action_view/base.rb:205:in `process_view_paths'         from /home/gditric/sandbox/ffl/vendor/actionmailer-2.3.4/lib/ action_mailer/base.rb:437:in `template_root='         from ./ffl.rb:66:in `<main>'

We’re in the process of reworking AM to work with the new AbstractController. One design goal is making the path to standalone use more clear. For your case, try require “action_controller” before trying to do any AM stuff :slight_smile:

– Yehuda

Thanks! I can now set the template_root with ActionMailer::Base.template_root=. However, it still is not finding my template. It looks like an Array is not getting initialized.

I not using rails framework, since this is not a rails app. So, I did not do the script/generate mailer Mailer to generate my Mailer class. I just manually created it in my app's framework. Is there something in rails or the generate script that is not getting set because I'm not in rails. Do I need to create a controller class? I don't remember having one with my limited rails development work a few years ago. I thought it was decoupled from ActionController.

Here is my class. When I call Mailer.deliver_results(team, week) looping a teams collections, I get the new error. require 'action_controller'

class Mailer < ActionMailer::Base    def results(team, week)     recipients team.email     from "commissioner@ffl.net"     subject "TPL: #{week.description} Results"     body :team => team, :week => week   end end

/home/gditric/sandbox/ffl/vendor/gems/1.9.1/gems/actionmailer-2.3.4/ lib/action_mailer/base.rb:582:in `candidate_for_layout?': undefined method `find_template' for :Array (NoMethodError)         from /home/gditric/sandbox/ffl/vendor/gems/1.9.1/gems/ actionpack-2.3.4/lib/action_controller/layout.rb:240:in `pick_layout'         from /home/gditric/sandbox/ffl/vendor/gems/1.9.1/gems/ actionmailer-2.3.4/lib/action_mailer/base.rb:566:in `render'         from /home/gditric/sandbox/ffl/vendor/gems/1.9.1/gems/ actionmailer-2.3.4/lib/action_mailer/base.rb:553:in `render_message'         from /home/gditric/sandbox/ffl/vendor/gems/1.9.1/gems/ actionmailer-2.3.4/lib/action_mailer/base.rb:493:in `create!'         from /home/gditric/sandbox/ffl/vendor/gems/1.9.1/gems/ actionmailer-2.3.4/lib/action_mailer/base.rb:452:in `initialize'         from /home/gditric/sandbox/ffl/vendor/gems/1.9.1/gems/ actionmailer-2.3.4/lib/action_mailer/base.rb:395:in `new'         from /home/gditric/sandbox/ffl/vendor/gems/1.9.1/gems/ actionmailer-2.3.4/lib/action_mailer/base.rb:395:in `method_missing'         from ./ffl.rb:104:in `block in <main>'         from ./ffl.rb:103:in `each'         from ./ffl.rb:103:in `<main>'

Thanks again. I'm getting further...and still experimenting. :wink:

GregD

Okay, I tried to add a controller but don't know how to outside of rails. A controller for a batch process should not be necessary, right? Googling for answers and no one mentions using a controller and most post are over 1-2 years old. Should I try a lower version of ActionMailer, ActonPack, etc.? Or, do I just neet to initialize something? If someone could point me to some documentation that would be great.

Later,

GregD

Okay, after trial and error I found my user error and all I have to say is duh...to the dumbazz (me)!

I was loading my classes (models) and then setting the template_root. Make sure you set ActionMailer::Base.template_root= BEFORE you load YourMailer class.

Also, I did a "require 'action_mailer'" instead of "require 'actionmailer'" <= this was causing me to require the action_controller and I did not have to do that once I fixed...oh boy...duh again. Hard to see the forest thru the trees sometimes.

It is now finding my templates and such and I will see how much further I get and then maybe put a sampe out some place on:

"Howto: Use ActionMailer outside rails"

All, I can say is sorry for my stupidity.

--GregD