Thursday, 5 September 2013

"wrong argument type" exception when using ActionMailer in Rails 3

"wrong argument type" exception when using ActionMailer in Rails 3

I'm totally lost on this one. In a Rails 3.2.12 app, I'm trying to send an
email with ActionMailer and getting this exception:
TypeError: wrong argument type Class (expected Module) from
/Users/trcull/.rvm/gems/ruby-1.9.3-p125@featureviz/gems/actionpack-3.2.12/lib/abstract_controller/helpers.rb:153:in
`include'
I've stripped my mailer down to bare minimum. It doesn't even send mail!
Here it is in its entirety:
class SupportNewUserMailer < ActionMailer::Base
def new_user
puts "hi"
end
end
Seriously, that's it. Then I call it from the Rails console like this and
get the exception:
1.9.3p125 :001 > SupportNewUserMailer.new_user
No idea what's going on here. I have another mailer in the same app and it
works fine.
Also, in case they are relevant, here's my configuration in development:
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.smtp_settings = {
:authentication => :plain,
:address => "smtp.mailgun.org",
:port => 587,
:domain => "redacted",
:user_name => "redacted",
:password => "redacted"
}
PS: yes, I tried declaring it as a class method (even though the docs say
not to) and get the same result:
class SupportNewUserMailer < ActionMailer::Base
def self.new_user
puts "hi"
end
end
Yields:
TypeError: wrong argument type Class (expected Module) from
/Users/trcull/.rvm/gems/ruby-1.9.3-p125@featureviz/gems/actionpack-3.2.12/lib/abstract_controller/helpers.rb:153:in
`include'
PPS: no, it's not a problem finding the class. If I change the declaration
to this (note, no longer inheriting from ActionMailer::Base):
class SupportNewUserMailer
def self.new_user
puts "hi"
end
end
Then I can call it just fine with no errors and it prints "hi" to the
screen as expected:
1.9.3p125 :001 > SupportNewUserMailer.new_user
hi
=> nil
1.9.3p125 :002 >

No comments:

Post a Comment