Ruby on rails 4 Rails::MailerController#预览中的ArgumentError(参数数量错误(1代表0))
我正在学习Rails教程的第10章。我跳过了帐户激活并实现了密码重置邮件程序。以下是用户_mailer_preview.rb的代码Ruby on rails 4 Rails::MailerController#预览中的ArgumentError(参数数量错误(1代表0)),ruby-on-rails-4,actionmailer,railstutorial.org,Ruby On Rails 4,Actionmailer,Railstutorial.org,我正在学习Rails教程的第10章。我跳过了帐户激活并实现了密码重置邮件程序。以下是用户_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/ma
# 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
#在http://localhost:3000/rails/mailers/user_mailer
类UserMailerPreview
以下是用户邮件程序本身的代码:
class UserMailer < ActionMailer::Base
default from: "from@example.com"
# 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: "to@example.org"
end
end
class UserMailer
当我转到http://localhost:3000/rails/mailers/user_mailer/password_reset
我正在接受
我做错了什么?您正在调用
UserMailer.password\u reset(user)
并传入用户
但是您的密码\u reset
方法不带参数。因此,要么您需要更改密码,要么您需要重置密码,以获取用户(并对其进行处理)
或者在没有用户的情况下,将您的呼叫调整为
UserMailer.password\u reset
对于由于方法需要参数但未提供参数而到达此处的任何人,您可以通过更改默认预览来修复此问题,以便为您提供给mailer方法的参数提供一些默认数据
有一个精彩的代码解释
def password_reset(user)
#do something with the user, such as send to their email address
@greeting = "Hi"
mail to: user.email
end