簡體   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