I finally came up with a solution. Here is my code that I wrote for inside the "create" method in my comments controller:
respond_to do |format|
if @comment.save
format.html { redirect_to @post, notice: 'Comment was successfully created.' }
format.json { render json: @comment, status: :created, location: @comment }
@commenter = @post.comments.collect(&:user)
@commenter = @commenter.uniq
@commenter.each do |commenter|
MyMailer.commenter_email(commenter).deliver
end
else
format.html { render action: "new" }
format.json { render json: @comment.errors, status: :unprocessable_entity }
end
end
So @commenter is collecting an array of all of the users who commented on that post. I then had to make @commenter equal @commenter.uniq so that when a user comments 3 times on a post, they don't get three emails whenever someone else comments.
Then I just made a mailer view and a commenter_email method in my_mailer.rb
The only issue is that it if you are the first person who comments, you'll get an email too, since I included the mailer after the "save" in the controller.