I'm trying to use actionmailer to notify me when a new comment has been posted but I keep getting the error:
我正在尝试使用actionmailer在发布新评论时通知我,但我一直收到错误消息:
uninitialized constant CommentsController::CommentMailer
The comment is added to my database and can be viewed. I am also using devise and it's email functions are working fine.
评论已添加到我的数据库中,可以查看。我也在使用设计,它的电子邮件功能正常。
My comment mailer:
我的评论邮件:
class CommentMailer < ActionMailer::Base
def newcomment(comment)
mail(:to => "admin@example.com", :subject => "New Comment")
end
end
and my controller section:
和我的控制器部分:
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
2 个解决方案
#1
13
This can also happen if you name your mailer file wrong. UserMailer.rb
will break whereas user_mailer.rb
is what is expected.
如果您将邮件程序文件命名为错误,也会发生这种情况。 UserMailer.rb将中断,而user_mailer.rb是预期的。
#2
3
OK my bad, I had to restart my rails application after I added the mailer. It is working fine now
好吧我的坏,我添加邮件后我不得不重新启动我的rails应用程序。现在工作正常
#1
13
This can also happen if you name your mailer file wrong. UserMailer.rb
will break whereas user_mailer.rb
is what is expected.
如果您将邮件程序文件命名为错误,也会发生这种情况。 UserMailer.rb将中断,而user_mailer.rb是预期的。
#2
3
OK my bad, I had to restart my rails application after I added the mailer. It is working fine now
好吧我的坏,我添加邮件后我不得不重新启动我的rails应用程序。现在工作正常