您好我正在尝试按照本指南实施联系表单:Contact form in 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
NotificationMailer
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
答案 0 :(得分:2)
您有notification_mailer.rb
- class NotificationMailer < ActionMailer::Base
更改此项(删除s)
NotificationsMailer.new_message(@message).deliver
要
NotificationMailer.new_message(@message).deliver