梅勒行动错误

时间:2014-03-01 13:29:07

标签: ruby-on-rails ruby ruby-on-rails-4

我写了一封邮件,它正好无助。但是我遇到了调用邮件工作的问题。

在评论正文中创建评论时,对于@someusername的每次提及,如果该用户退出,则会向他们的电子邮件地址发送电子邮件。

这就是我所拥有的:

def create
  @commentable = find_commentable
  @comment = @commentable.comments.build(params[:comment])
  @comment.user = current_user
  if @comment.save
    flash[:notice] = "Successfully created comment."
    redirect_to @commentable

      end
    end

  else
    render :action => 'new'
  end

这是我不断得到的错误:

undefined method `email' for nil:NilClass

错误来自(邮件内部):

    @user = user
    @url  = 'http://domain.com'
    mail(to: @user.email)
  end
end

2 个答案:

答案 0 :(得分:2)

email被调用为@user,而@user将始终为零。

看看这一行:

unless @user_check = nil

使用单个equals是赋值,而不是相等比较。

您想要这样做:

unless @user_check == nil

或更具有情感的Ruby:

unless @user_check.nil?

答案 1 :(得分:1)

unless @user_check = nil语句进行检查: -

=是赋值,==是相等比较运算符。我猜你因为拼写错误而错过使用==

请改用ruby .nil?方法。

喜欢unless @user_check.nil?

使用delayed_job发送电子邮件。