我注意到我的CustomMailer(ActionMailer的子类)上出现了非常奇怪的行为:
class CustomMailer < ActionMailer::Base
def deliver(template) # with ":greeting" passed as argument
# WORKS: Renders view app/views/custom_mailer/greeting
CustomMailer.send(template)
# BROKEN: Does not render view app/view/custom_mailer/greeting
self.send(template)
end
def greeting # this gets called by both invocations, but
# only the former renders the view. Why?
...
mail(to: ...
为什么第一个渲染但不渲染第二个?以下是我的假设:
send
无法调用self
self
和实例方法与CustomMailer和类方法的内容?答案 0 :(得分:0)
ActionMailer :: Base overloads the class' method_missing而是创建一个实例,最终调用实例方法和/或呈现视图。