0

我正在升级 rails 2.3.2 app ot rails 3。在 MailerFormError 中发送电子邮件时出现未知错误。MailerFormError 是我的模型: class MailerFormError < ActionMailer::Base

在第一次我有'deliver_send'方法错误(未定义方法'deliver_sent' for MailerFormError:Class),我将其更改为'send'。现在我有这个:



   NoMethodError in LeadsController#create
   undefined method `part' for #

我在控制器中的代码:



    @msg = {}
    @msg["errors"] = @lead.errors
    @msg["params"] = params
    #MailerFormError.deliver_sent(@msg)
    MailerFormError.sent(@msg)

这是我的发送方法类:



      def sent(msg, sent_at = Time.now)
        @subject    = ("Ошибка при заполнении формы").force_encoding('iso-8859-1').encode('utf-8')
        @recipients = 'mymail@gmail.com'
        @from       = 'mymail@gmail.com'
        @sent_on    = sent_at
        @headers    = {}

        part( :content_type => "multipart/alternative" ) do |p|
          p.part :content_type => "text/plain", 
                 :body => render_message("sent.plain.erb", :msg=>msg )
        end

      end
4

1 回答 1

0

1) 对于 Rails 3,要在控制器中发送通知,您必须这样写:

MailerFormError.sent(@msg).deliver

2)并且您必须以Rails 3 方式重写您的“发送”方法:

def sent(msg, sent_at = Time.now)
  ...
  mail(:to => '...', :from => '...', :subject => '...') do |format|
    format.html
    format.text
  end
  ...
end

您还可以在视图目录 app/views/mail_form_error 中创建文本版本和 html:send.text.erb 和 sent.html.erb

于 2013-03-26T13:38:34.883 回答