您好,我正在尝试按照本指南实施联系表格:Rails 3 中的联系表格
我没有使用谷歌应用程序,而是使用 1and1 的 smtp。
我尝试发送表单时遇到的错误是
Processing by ContactController#create as HTML
Parameters: {"utf8"=>"✓",
"authenticity_token"=>"N48ORAhmDqTO7X2wsRlslMJ3l+v=", "message"=>{"name"=>"Patrick", "email"=>"patrick@yahoo.com", "subject"=>"Hello", "body"=>"Hello ME"}, "commit"=>"Send"}
NameError (uninitialized constant ContactController::NotificationsMailer):
app/controllers/contact_controller.rb:11:in `create'
经过一些调整尝试后,我最终只是复制并粘贴了指南中的代码。还是有问题。
class ContactController < ApplicationController
def new
@message = Message.new
end
def create
@message = Message.new(params[:message])
if @message.valid?
NotificationsMailer.new_message(@message).deliver
redirect_to(root_path, :notice => "Message was successfully sent.")
else
flash.now.alert = "Please fill all fields."
render :new
end
end
end
通知邮件程序
class NotificationMailer < ActionMailer::Base
default from: "noreply@misawahousing.com"
default to: "info@misawahousing.com"
def new_message(message)
@message = message
mail(subject: "[misawahousing.com] #{message.subject}")
end
end