【问题标题】:wrong number of arguments (given 0, expected 1) in Rails 5Rails 5 中的参数数量错误(给定 0,预期为 1)
【发布时间】:2017-12-14 10:44:01
【问题描述】:

我正在使用 Action Mailer 在使用 devise 的 rails 应用程序中发送电子邮件。我的user mailer.rb 文件包含此代码

class UserMailer < ApplicationMailer
  def signup_confirmation(user)
    @user = user
    mail to: @user.email
  end
end

但是我得到了这个错误

wrong number of arguments (given 0, expected 1)

【问题讨论】:

  • 请分享您调用此函数的代码?

标签: ruby-on-rails ruby devise


【解决方案1】:

你可能有这样的东西。看评论

class MailerController < ApplicationController
  def preview
    UserMailer.signup_confirmation # miss the user parameter
  end
end

【讨论】:

    【解决方案2】:

    调用UserMailer.signup_confirmation 的代码显然没有传递所需的user 参数。

    您必须修复调用代码才能将用户传递给方法。您可以在堆栈跟踪中找到调用代码(即错误页面和日志中的“应用程序跟踪”或“完整跟踪”链接。

    【讨论】:

    • 我看到了数据保存在数据库中但电子邮件未发送的跟踪
    猜你喜欢
    • 1970-01-01
    • 2020-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多