2013-06-19 37 views
0

你好,我想實現這個指南聯絡表格: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 
+0

您是否重新啓動服務器? –

+0

請問您可以粘貼控制器操作代碼嗎? –

+0

@ Michael Szyndel編輯原始問題 – Patrick

回答

2

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

改變這種(刪除S)

NotificationsMailer.new_message(@message).deliver 

NotificationMailer.new_message(@message).deliver 
+0

謝謝你沒有看到錯字,但現在我遇到了這個問題的錯誤。 http://stackoverflow.com/questions/14051056/rails-3-2-8-actionmailer-stack-level-too-deep-plus-uninitialized-constant-mail – Patrick

+1

如果你發現了一個新問題,你可以提出一個新問題並接受答案或您在這些問題上發佈解決方案 –

相關問題