联系表格未初始化的常数联系控制器

时间:2013-06-19 15:10:06

标签: ruby-on-rails contact-form uninitialized-constant

您好我正在尝试按照本指南实施联系表单: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

1 个答案:

答案 0 :(得分:2)

您有notification_mailer.rb - class NotificationMailer < ActionMailer::Base

更改此项(删除s)

 NotificationsMailer.new_message(@message).deliver

 NotificationMailer.new_message(@message).deliver