Mailer Generating Syntax Error: unexpected '\n', expecting :: or '[' or '.'

Mailer Generating Syntax Error: unexpected '\n', expecting :: or '[' or '.'

我正在尝试从我的 Contact 模型创建一个邮件程序 (ContactMailer),它将信息从基本表单保存到数据库。它已正确保存到数据库,但我的邮件程序方法出现错误。

正在调用 syntax error, unexpected '\n', expecting :: or '[' or '.',突出显示我的模型代码的第一个 end

class Contact < ActiveRecord::Base
  after_create :send_contact_emails

  private

  def send_contact_emails
    for contacts do |contact|
      ContactMailer.new_contact(name, email, message).deliver_now
    end
  end
end

这是我的 contact_mailer.rb 代码:

class ContactMailer < ApplicationMailer
  default from: "geneticgolf@gmail.com"

  def new_contact(name, email, comment)
    @contact.name = name
    @contact.email = email
    @contact.message = message

    mail(to: "EMAILADDRESS@gmail.com", subject: "New Contact Us Submission from #{name}")
  end
end

我们将不胜感激,因为我大量的谷歌搜索没有解决问题。

试试这个:

class Contact < ActiveRecord::Base
 after_create :send_contact_emails

private

 def send_contact_emails
    ContactMailer.new_contact(self).deliver_now 
 end
end

和:

 class ContactMailer < ApplicationMailer
  default from: "geneticgolf@gmail.com"

 def new_contact(contact)
  @contact = contact
  mail(to: "EMAILADDRESS@gmail.com", subject: "New Contact Us Submission from #{@contact.name}")
 end
end