2012-02-13 73 views
5

我試圖使用的ActionMailer通知我,當一個新的評論已發佈,但我不斷收到錯誤:Rails 3的動作梅勒未初始化不斷

uninitialized constant CommentsController::CommentMailer 

註釋添加到我的數據庫,並可以查看。我也在使用設計,它的電子郵件功能工作正常。

我的評論郵件:

class CommentMailer < ActionMailer::Base 
    def newcomment(comment) 
    mail(:to => "[email protected]", :subject => "New Comment") 
    end 
end 

和我的控制器部分:

def create 
    @comment = Comment.new(params[:comment]) 
    @comment.user_id = current_user.id 

respond_to do |format| 
    if @comment.save 
    CommentMailer.newcomment(@comment).deliver 
    format.html { redirect_to @comment, notice: 'Comment was successfully created!' } 
    format.json { render json: @comment, status: :created, location: @comment } 
    else 
    format.html { render action: "new" } 
    format.json { render json: @comment.errors, status: :unprocessable_entity } 
    end 
end 
end 
+3

您的錯誤消息用s表示「CommentsMailer」,而您的代碼表示CommentMailer。這個錯誤肯定來自這個代碼嗎?你能找出錯誤來自堆棧跟蹤的行嗎? – Shadwell 2012-02-13 23:03:08

+0

對不起,當我問我的問題時已經很晚了。它是「CommentMailer」而不是「CommentsMailer」否「s」 – Steve 2012-02-14 19:07:55

回答

3

OK是我不好,我不得不重新啓動我的Rails應用程序後,我加入了郵件。它現在工作正常

13

這也可能發生,如果你錯誤地命名你的郵件文件。 UserMailer.rb會中斷,而user_mailer.rb是預期的。

相關問題