![](/img/trans.png)
[英]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
感謝您的廣泛使用Google的技巧仍無法解決問題,因此可以幫助您完成此工作。
嘗試這個:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.