Rails 3 Action Mailer未初始化的常量

Ste*_*eve 5 ruby-on-rails actionmailer

我正在尝试使用actionmailer在发布新评论时通知我,但我一直收到错误消息:

uninitialized constant CommentsController::CommentMailer
Run Code Online (Sandbox Code Playgroud)

评论已添加到我的数据库中,可以查看.我也在使用设计,它的电子邮件功能正常.

我的评论邮件:

class CommentMailer < ActionMailer::Base
  def newcomment(comment)
  mail(:to => "admin@example.com", :subject => "New Comment")  
  end  
end
Run Code Online (Sandbox Code Playgroud)

和我的控制器部分:

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
Run Code Online (Sandbox Code Playgroud)

Uri*_*Uri 13

如果您将邮件程序文件命名为错误,也会发生这种情况.UserMailer.rb将会破裂,而user_mailer.rb预期却是如此.


Ste*_*eve 4

好吧,我的错,添加邮件程序后我必须重新启动我的 Rails 应用程序。现在工作正常