你好,我想實現這個指南聯絡表格:Contact form in Rails 3聯繫表未初始化的常量的ContactController
我沒有使用谷歌應用程序,但的1and1的SMTP。
我得到當我嘗試發送表單的錯誤是
Processing by ContactController#create as HTML
Parameters: {"utf8"=>"✓",
"authenticity_token"=>"N48ORAhmDqTO7X2wsRlslMJ3l+v=", "message"=>{"name"=>"Patrick", "email"=>"[email protected]", "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: "[email protected]"
default to: "[email protected]"
def new_message(message)
@message = message
mail(subject: "[misawahousing.com] #{message.subject}")
end
end
您是否重新啓動服務器? –
請問您可以粘貼控制器操作代碼嗎? –
@ Michael Szyndel編輯原始問題 – Patrick