我正在尝试使用 actionmailer 在发布新评论时通知我,但我不断收到错误:
uninitialized constant CommentsController::CommentMailer
该评论已添加到我的数据库中并且可以查看。我也在使用 devise,它的电子邮件功能运行良好。
我的评论邮件:
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
如果您的邮件程序文件命名错误,也可能会发生这种情况。UserMailer.rb
会打破而user_mailer.rb
这是所期望的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)