繁体   English   中英

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

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

我是Rails的新手,我正在制作一个应用程序,用户可以在其中创建帖子。 我试图在用户发布帖子后触发确认电子邮件。...但我一直收到此NoMethod错误:

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

我尝试重新启动,甚至没有传递参数。 我不知道发生了什么事。 据我所知,我的ActionMailer逻辑未包含在“私有方法”中。

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

所以...这完全是我的问题。 我像这样在“类PostMailer <ActionMailer :: Base”下离开并“结束”。 所以我的逻辑是正确的,但是我的错误是在可以读取逻辑之前结束了该类。 简单的错误,数小时的头痛。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM