简体   繁体   English

Mailer生成语法错误:意外的'\\ n',期望::或'['或'。

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

I am trying to create a mailer ( ContactMailer ) from my Contact model, which saves information from a basic form to the database. 我正在尝试从我的Contact模型创建一个邮件程序( ContactMailer ),该程序将信息从基本表单保存到数据库中。 It is correctly saving to the database, but I'm getting an error for my mailer method. 它已正确保存到数据库,但是我的邮递员方法出现错误。

It's calling syntax error, unexpected '\\n', expecting :: or '[' or '.' 它正在调用syntax error, unexpected '\\n', expecting :: or '[' or '.' , highlighting the first end of my model code: ,突出显示我的模型代码的第一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

Here's my contact_mailer.rb code: 这是我的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

Any help getting this working would be appreciated, as my extensive googling has not done the trick. 感谢您的广泛使用Google的技巧仍无法解决问题,因此可以帮助您完成此工作。

Try this: 尝试这个:

class Contact < ActiveRecord::Base
 after_create :send_contact_emails

private

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

and: 和:

 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM