2012-02-13 31 views
5

Tôi đang cố gắng sử dụng ActionMailer để thông báo cho tôi khi có bình luận mới đã được đăng nhưng tôi tiếp tục nhận được lỗi:Rails 3 Action Mailer uninitialized liên tục

uninitialized constant CommentsController::CommentMailer 

Các bình luận được thêm vào cơ sở dữ liệu của tôi và có thể đã xem. Tôi cũng đang sử dụng thiết lập và các chức năng email của nó đang hoạt động tốt.

My comment bưu phẩm:

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

và phần điều khiển của tôi:

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

Thông báo lỗi của bạn cho biết "CommentsMailer" có chữ s trong khi mã của bạn cho biết CommentMailer. Lỗi chắc chắn đến từ mã này phải không? Bạn có thể xác định dòng nơi lỗi xuất phát từ stacktrace không? – Shadwell

+0

Xin lỗi đã đến muộn khi tôi hỏi câu hỏi của tôi. nó là "CommentMailer" Không phải "CommentsMailer" no "s" – Steve

Trả lời

3

OK xấu của tôi, tôi phải khởi động lại ứng dụng ray của tôi sau khi tôi thêm các bưu phẩm. Nó hiện đang hoạt động tốt

13

Điều này cũng có thể xảy ra nếu bạn đặt tên cho tệp bưu phẩm của mình sai. UserMailer.rb sẽ bị ngắt trong khi user_mailer.rb là những gì được mong đợi.

Các vấn đề liên quan