Rails 3 Action Mailer uninitialized constant

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

uninitialized constant CommentsController::CommentMailer

A comment has been added to my database and can be viewed. I also use the program, and the email functions are working fine.

My comment:

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
+5
source share
2 answers

This can also happen if you incorrectly name your zip file. UserMailer.rbwill be broken, whereas user_mailer.rb- this is what is expected.

+13
source

Well, which is bad, I had to restart the rails app after adding the mailer. Now it works great

+3

All Articles