我是rails的新手,我正在创建一个用户可以创建帖子的应用。我试图在用户发布帖子后触发确认电子邮件....但我一直得到这个NoMethod错误:
"private method `add_post' called for PostMailer:Class"
我尝试重启,甚至没有通过params。我不知道发生了什么。据我所知,我的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 Logic
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
答案 0 :(得分:0)
所以......这完全是我的问题。我离开了&#34;结束&#34;在&#34;类PostMailer&lt;的ActionMailer :: Base的 &#34;像这样。所以我的逻辑是正确的,但我的错误是在读取逻辑之前结束了类。简单的错误,几个小时的头痛。
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