uninitialized constant ActionMailer
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.
My name is
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.
June 23rd, 2006 at 8:09 am (#)
Glad it helped you!
June 29th, 2006 at 8:45 pm (#)
Thanks for the tip. You saved me a good amount of time I’m sure.
November 9th, 2006 at 9:56 am (#)
Nice one. Just what I needed.
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
January 8th, 2007 at 12:23 am (#)
thanks andrew, it helped my time, i was wondering by seeing the error message.
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?
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.
March 30th, 2007 at 3:21 am (#)
What does NameError Uninitialized Constant mean anyway?
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
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.
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…
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.
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.
June 20th, 2007 at 8:55 pm (#)
Hello! Good Site! Thanks you! wlbsncvqxppo
June 27th, 2007 at 3:35 pm (#)
Thanks for this site!
hifue.info
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
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!
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.
December 6th, 2007 at 12:18 am (#)
[...] I found a solution here: http://highearthorbit.com/uninitialized-constant-actionmailer/ [...]
January 9th, 2008 at 7:09 am (#)
It has helped me too! Thanks a bunch.
January 10th, 2008 at 11:31 am (#)
Cheers!
January 17th, 2008 at 7:07 am (#)
Awsome! cheers mate
January 31st, 2008 at 2:09 pm (#)
Thanks!! You’re #1 on the google result for this error…
February 13th, 2008 at 12:02 pm (#)
Thank you for saving my sanity.
March 7th, 2008 at 6:53 am (#)
Woot! Thanks very much!
April 15th, 2008 at 7:43 am (#)
Oh!!! thanks a lot!
July 19th, 2008 at 9:31 pm (#)
Bless you, good sir.
August 29th, 2008 at 10:44 pm (#)
Thank you!
September 21st, 2008 at 1:17 pm (#)
Cheers Andrew, you just saved me a tonne of headaches…