Ruby on rails ActionMailer参数未传入预览

Ruby on rails ActionMailer参数未传入预览,ruby-on-rails,Ruby On Rails,我是Rails Action Mailer的新手,在配置我的第一封电子邮件时,我在访问后遇到此错误http://localhost:3000/rails/mailers/user_mailer/confirm_email: nil:NilClass的未定义方法“[]” @用户=参数[:用户] 我的代码: class UserMailer < ApplicationMailer def confirm_email @user = params[:user] mail to

我是Rails Action Mailer的新手,在配置我的第一封电子邮件时,我在访问后遇到此错误http://localhost:3000/rails/mailers/user_mailer/confirm_email:

nil:NilClass的未定义方法“[]” @用户=参数[:用户]

我的代码:

class UserMailer < ApplicationMailer
  def confirm_email
    @user = params[:user]
    mail to: "to@example.org"
  end
end

class UserMailerPreview < ActionMailer::Preview
  def confirm_email
    UserMailer.with(user: User.first).confirm_email
  end
end
我不明白,我做错了什么


我的rails版本是6.0.3.5

如果您确信您的数据库中至少有一条用户记录,我将尝试以下方法,这是您尝试的组合

class UserMailer < ApplicationMailer
  def confirm_email(user)
    @user = user
    mail to: "to@example.org"
  end
end

class UserMailerPreview < ActionMailer::Preview
  def confirm_email
    UserMailer.with(user: User.first).confirm_email
  end
end
class UserMailer
嘿!我的数据库中确实有用户,奇怪的是我试图通过控制台发送电子邮件,并且从那里开始工作。然后,它又开始工作了。所以我不知道是什么触发了它,但它只是在某个点随机开始工作。。。谢谢你的帮助!
wrong number of arguments (given 0, expected 1)
class UserMailer < ApplicationMailer
  def confirm_email(user)
    @user = user
    mail to: "to@example.org"
  end
end

class UserMailerPreview < ActionMailer::Preview
  def confirm_email
    UserMailer.with(user: User.first).confirm_email
  end
end