2017-02-03 58 views
0

我创建了一个新邮件使用的邮件生成轨道5:为什么我无法使用名为message的邮件程序方法?

$ rails g mailer mymailer message 

Rails的创建application_mailer,mymailer_mailer,观点和测试。好。

这是由轨道所产生的邮件:

NoMethodError: undefined method `reject!' for nil:NilClass 

花了大约两个小时后,双击:但每当我试图发送邮件,我得到了以下错误

class MymailerMailer < ApplicationMailer 

    # Subject can be set in your I18n file at config/locales/en.yml 
    # with the following lookup: 
    # 
    # en.mymailer_mailer.message.subject 
    # 
    def message 
    @greeting = "Hi" 

    mail to: "[email protected]" 
    end 
end 

- 检查每个配置文件我已决定将方法更改为bla ...

Voilà:它的工作,好的!但为什么?

顺便说一句:message我发现的方法是从ActionMailer::MessageDelivery,但没有提到Rails指南。

回答

1

如果你看看文档为MessageDelivery,似乎是已经提供了一个名为message方法,

Returns the resulting Mail::Message

我的假设是,你的定义是重写此提供的方法,但你不必返回预期的Mail :: Message类型对象。

0

如另一个回答所述,已经有一个名为message的类中的方法。如果按照预期使用类,这应该不成问题,因为邮件程序不应该有一个名为“message”的消息,它应该有一个更具描述性的名称。

Mailer对象的目的是为可能发送的消息定义上下文

因此,例如,UserMailer将用于构建消息给用户。然后,每种不同类型的消息都有一个方法,例如forgotten_passwordwelcome

该文档包括后面的a more thorough example

相关问题