Status
it's already here - checking in online vs. being down the hallway have only a minor difference
Location
Arlington, VA
Subscribe to GeoRSS Subscribe to KML


uninitialized constant ActionMailer

Published in Open-Source, Programming, Rails, Ruby, Technology  |  36 Comments


A word to the wise of rails developers. Hopefully this makes it to Google search, because when I looked it up, there wasn’t an answer.

If you’re configuring ActionMailer and you try to run the console and get the following messages:

[host]$ script/console
Loading development environment.
./script/../config/../config/environment.rb:41:NameError:
  uninitialized constant ActionMailer
/home/highearth/.gems/gems/actionpack-1.12.1/lib/action_controller/integration.rb:15:
  NameError: uninitialized constant ActionController::Integration::Session::Test
./script/../config/../config/../app/controllers/application.rb:3:
  NameError: uninitialized constant ActionController::Base

Make sure your ActionMailer configuration in your config/environment.rb file is after your Rails::Initializer.run do |config| block.

Similar Posts


Responses

  1. Andy says:

    June 23rd, 2006 at 3:15 am (#)

    Hi Andrew,

    Just wanted to say – excellent excellent tip. I’d reinstalled Ruby about 4 times trying to get ActionMailer to work; and all along it was just this config error. Rats!

    Well, it’s solved now – so thanks a bunch.

  2. Andrew says:

    June 23rd, 2006 at 8:09 am (#)

    Glad it helped you!

  3. Anthony Eden says:

    June 29th, 2006 at 8:45 pm (#)

    Thanks for the tip. You saved me a good amount of time I’m sure.

  4. Mike says:

    November 9th, 2006 at 9:56 am (#)

    Nice one. Just what I needed.

  5. ernst says:

    November 20th, 2006 at 10:40 am (#)

    thanks. it worked before but didn’t work afterwards… maybe because of an upgrade
    now it works again, thanks

  6. sarath says:

    January 8th, 2007 at 12:23 am (#)

    thanks andrew, it helped my time, i was wondering by seeing the error message.

  7. Micah says:

    January 21st, 2007 at 11:14 am (#)

    I had it inside the block for rails 1.1.6 and it worked. When I upgrade to 1.2.1, it stopped working.

    It wouldn’t be a big deal except that when it’s outside that block, the testing environment cannot set mail delivery to :test, which means that all my unit tests try to send e-mail through the SMTP server. They fail because the email addresses are bogus and not even legal (a@a.com).

    Any ideas?

  8. Micah says:

    January 21st, 2007 at 11:18 am (#)

    Well, luckily I’m using SMTP (the default). So, if I comment out the SMTP section, it will default to SMTP when necessary and use :test in the testing section.

    I guess you could put SMTP in the production and development environments manually.

  9. jonah says:

    March 30th, 2007 at 3:21 am (#)

    What does NameError Uninitialized Constant mean anyway?

  10. Arne says:

    April 15th, 2007 at 9:23 am (#)

    In Ruby a Class is just an object, usually these objects are assigned to constants, variables that start with an uppercase letter. So ActionMailer is a constant that contains an instance of Class, namely the ActionMailer class. Since ActionMailer hasn’t been intialized you get a NameError : Uninitialized Constant.

    Makes perfect sense :)

  11. Arne says:

    April 15th, 2007 at 9:24 am (#)

    But that hasn’t solved my problem : I’d like to use ActionMailer _without_ rails, so I can’t use the rails initializer.

  12. Eric Savage says:

    May 7th, 2007 at 5:15 am (#)

    And to add to that, for the Republic of Stupid People, of whom I am a citizen…

    Don’t remove the comment on:
    # config.frameworks -= [ :action_web_service, :action_mailer ]

    Right, with those wasted 2 hours out of my way, let’s code… :)

  13. Andrew says:

    May 7th, 2007 at 9:41 am (#)

    @Eric – Yeah, that will make it rather difficult for ActionMailer to work, when it’s been told to not be used. :)

  14. Adrian says:

    May 8th, 2007 at 10:25 pm (#)

    Thank you Sir! I’m sure you saved me some time there. Thank goodness I googled and found this.

  15. dbxrsziqxa says:

    June 20th, 2007 at 8:55 pm (#)

    Hello! Good Site! Thanks you! wlbsncvqxppo

  16. spdnwjeakg says:

    June 27th, 2007 at 3:35 pm (#)

    Thanks for this site!
    hifue.info

  17. escoz says:

    August 26th, 2007 at 1:14 pm (#)

    Thanks a lot for the tip!!

    By the way, first hit on google for the query! :)

    Best regards,

    escoz

  18. nicole says:

    September 19th, 2007 at 4:40 pm (#)

    ok – in case anyone out there is a complete idiot like me – notice the instructions say to place the code following the config BLOCK. I was putting the code after the LINE, not the BLOCK. Whew – 24 hours later and I’m back in business!

  19. Ben says:

    December 6th, 2007 at 12:11 am (#)

    Thanks for the tip. This worked a treat.

    For some reason – having the directive in the block was working on an Apache fcgi server, but upon migrating to Mongrel I got this error.

  20. Bens Blog » Uninitialized ActionMailer says:

    December 6th, 2007 at 12:18 am (#)

    [...] I found a solution here: http://highearthorbit.com/uninitialized-constant-actionmailer/  [...]

  21. Logo Designer says:

    January 9th, 2008 at 7:09 am (#)

    It has helped me too! Thanks a bunch.

  22. paulie says:

    January 10th, 2008 at 11:31 am (#)

    Cheers!

  23. bzouchir says:

    January 17th, 2008 at 7:07 am (#)

    Awsome! cheers mate

  24. Anthony says:

    January 31st, 2008 at 2:09 pm (#)

    Thanks!! You’re #1 on the google result for this error…

  25. peter says:

    February 13th, 2008 at 12:02 pm (#)

    Thank you for saving my sanity.

  26. James says:

    March 7th, 2008 at 6:53 am (#)

    Woot! Thanks very much!

  27. Dag Stensson says:

    April 15th, 2008 at 7:43 am (#)

    Oh!!! thanks a lot!

  28. drew says:

    July 19th, 2008 at 9:31 pm (#)

    Bless you, good sir.

  29. René says:

    August 29th, 2008 at 10:44 pm (#)

    Thank you!

  30. Les says:

    September 21st, 2008 at 1:17 pm (#)

    Cheers Andrew, you just saved me a tonne of headaches…

  31. Fred Obermann says:

    February 23rd, 2009 at 11:05 pm (#)

    Here it is 2009, I have just finished reading the 2008 edition of the “Rails Way”, and and Obie has devoted a whole 8 lines the the Actionmailer::Base.smtp_settings without once mentioning WHERE IN THE environment.rb file they are to be placed!

    The lack of these kinds of details in the documentation have driven me to commit suicide by jumping out of the window 17 times in the last month. Thank God I live and work in a basement apartment.

    Most the the time I think Rails is insanely brilliantly, but there are times when I think it it just plain insane.

    Thank you Andrew.

  32. Matt says:

    March 7th, 2009 at 5:54 pm (#)

    Huge help on that hint, would have taken me a while to realize. You are indeed the first google hit.

  33. patrick says:

    March 11th, 2009 at 5:01 am (#)

    thx alot :)
    You saved my day ;)

  34. davidpthomas says:

    August 26th, 2009 at 12:17 am (#)

    yep – me too. thx for the tip.

  35. Maryjane says:

    September 17th, 2009 at 4:59 pm (#)

    Wow! I can’t tell you how many tips and instructions, and how-to’s I have looked at never to find the place I should be putting the code… thanks a bunch!

  36. Ben says:

    January 2nd, 2010 at 6:35 pm (#)

    Thanks, this was a little bit tricky, as all the example code was already inside the init block!

Leave a Response