Reputation: 400
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 >
Upvotes: 1
Views: 719
Reputation: 400
I have a partial answer to my own question, though I don't understand why it works and would love to know a better explanation.
If I simply use a different name for my class, it works fine. So, for example, this works fine:
class NewUserMailer < ActionMailer::Base
def new_user()
puts "hi"
end
end
Which would seem to suggest that using the word "Support" at the beginning of the class name is bad. But I tried a different class name that also starts with "Support" and that works fine, too:
class SupportStackOverflowMailer < ActionMailer::Base
def new_user()
puts "hi"
end
end
It's just specifically the name "SupportNewUserMailer" that it doesn't like. I've confirmed that I don't have a different class with the same name anywhere in my project (though who knows if a gem does?). Is there some kind of class meta cache thing that's borked?
EDIT:
Finally figured it out. I had a "SupportNewUserMailerHelper" class declared under /lib. Apparently Rails was trying to associate that class as a helper for my mailer class through some automagical wizardty that was exploding. Deleting the helper class got rid of the problem.
Upvotes: 1