gpt4 book ai didi

ruby-on-rails-4 - Rails::MailersController#preview 中的 ArgumentError(参数数量错误(1 代表 0))

转载 作者:行者123 更新时间:2023-12-02 21:21:09 24 4
gpt4 key购买 nike

我正在研究 Rails 教程的第 10 章。我已经跳过了帐户激活并实现了密码重置邮件程序。这是 user_mailer_preview.rb 的代码:

# Preview all emails at http://localhost:3000/rails/mailers/user_mailer
class UserMailerPreview < ActionMailer::Preview

# Preview this email at
# http://localhost:3000/rails/mailers/user_mailer/password_reset
def password_reset
user = User.first
user.reset_token = User.new_token
UserMailer.password_reset(user)
end
end

这是用户邮件程序本身的代码:

class UserMailer < ActionMailer::Base
default from: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0d6b7f62604d68756c607d6168236e6260" rel="noreferrer noopener nofollow">[email protected]</a>"

# Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup:
#
# en.user_mailer.password_reset.subject
#
def password_reset
@greeting = "Hi"

mail to: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="53273c13362b323e233f367d3c2134" rel="noreferrer noopener nofollow">[email protected]</a>"
end
end

当我访问http://localhost:3000/rails/mailers/user_mailer/password_reset时,我得到了

ArgumentError in Mailer

我做错了什么?

最佳答案

您正在调用UserMailer.password_reset(user)并传入用户

但是您的 password_reset 方法不接受参数。因此,您要么需要更改您的password_reset以获取用户(并用它做一些事情)

def password_reset(user)
#do something with the user, such as send to their email address
@greeting = "Hi"
mail to: user.email
end

或者将您的调用调整为UserMailer.password_reset,无需用户。

关于ruby-on-rails-4 - Rails::MailersController#preview 中的 ArgumentError(参数数量错误(1 代表 0)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27620926/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com