【问题标题】:Rails 3 Action Mailer uninitialized constantRails 3 Action Mailer 未初始化常量
【发布时间】:2012-02-13 22:55:49
【问题描述】:

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

uninitialized constant CommentsController::CommentMailer

评论已添加到我的数据库中,可以查看。我也在使用设计,它的电子邮件功能运行良好。

我的评论邮件:

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

【问题讨论】:

  • 您的错误消息显示带有 s 的“CommentsMailer”,而您的代码显示的是 CommentMailer。错误肯定来自此代码吗?你能从堆栈跟踪中找出错误的来源吗?
  • 抱歉,我的问题来晚了。它是“CommentMailer”而不是“CommentsMailer”没有“s”

标签: ruby-on-rails actionmailer


【解决方案1】:

如果您将邮件文件命名错误,也会发生这种情况。 UserMailer.rb 将中断,而 user_mailer.rb 是预期的。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2013-04-17
      • 1970-01-01
      • 2011-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-04
      相关资源
      最近更新 更多