Rails 3 Action Mailer未初始化的常量 [英] Rails 3 Action Mailer uninitialized constant

查看:83
本文介绍了Rails 3 Action Mailer未初始化的常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

发布新评论后,我尝试使用actionmailer通知我,但我不断收到错误消息:

I'm trying to use actionmailer to notify me when a new comment has been posted but I keep getting the error:

uninitialized constant CommentsController::CommentMailer

该注释已添加到我的数据库中并且可以查看。我也在使用devise,它的电子邮件功能也可以正常工作。

The comment is added to my database and can be viewed. I am also using devise and it's email functions are working fine.

我的评论邮件:

class CommentMailer < ActionMailer::Base
  def newcomment(comment)
  mail(:to => "admin@example.com", :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 是预期的。

This can also happen if you name your mailer file wrong. UserMailer.rb will break whereas user_mailer.rb is what is expected.

这篇关于Rails 3 Action Mailer未初始化的常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆