NoMethod 错误私有方法 ActionMailer rails 4 记录保存后发送电子邮件

NoMethod Error private method ActionMailer rails 4 sending email after record save

我是 rails 的新手,我正在制作一个用户可以创建 Post 的应用程序。我正在尝试在用户发布 Post 后触发确认电子邮件......但我不断收到此 NoMethod 错误:

"private method `add_post' called for PostMailer:Class"

我试过重启甚至不传递参数。我不知道是怎么回事。据我所知,我的 ActionMailer 逻辑没有包含在 'private method'...

class PostsController < ApplicationController

  def add_post
    @magazine = Magazine.find(params[:m])
    @post = Post.new(post_params)

    respond_to do |format|
      if @post.save
        PostMailer.add_post(@post, @magazine, current_user).deliver
        format.html { redirect_to postadded_path(), notice: "Post Added."}
        format.json { render :show, status: :created, location: @post }
      else
        render :new
      end
    end
  end

ActionMailer 逻辑

class PostMailer < ActionMailer::Base
  def add_post(post, magazine, current_user)
    @magazine = magazine
    @post = post
    @recipient = current_user.email
    mail(to: @recipient, subject: 'You've Posted an Article',   sent_on: Time.now,   template_path: 'add_post_email') 

  end

所以...这完全是我的问题。我在“class PostMailer < ActionMailer::Base 下面离开了 "end" ” 就像这样。所以我的逻辑是正确的,但我的错误是在逻辑可以被读取之前结束 class。简单的错误,令人头疼的时间。

class PostMailer < ActionMailer::Base
end 

def add_post(post, magazine, current_user)
    @magazine = magazine
    @post = post
    @recipient = current_user.email
    mail(to: @recipient, subject: 'You've Posted an Article',   sent_on: Time.now,   template_path: 'add_post_email') 
  end