【发布时间】:2015-01-05 07:53:50
【问题描述】:
我是 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.send(:add_post, @post, @magazine, current_user).deliver -
谢谢你的回答,我刚刚回来把我有的和额外的“end”放在“class PostMailer
标签: ruby-on-rails ruby-on-rails-4 actionmailer nomethoderror