Nic*_*ick 2 actionmailer railstutorial.org ruby-on-rails-4
I am working on Chapter 10 of the Rails Tutorial. I've skipped the account activation and implemented the password reset mailer. Here is the code: of 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
Run Code Online (Sandbox Code Playgroud)
Here is the code of the user mailer itself:
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
Run Code Online (Sandbox Code Playgroud)
当我去的时候http://localhost:3000/rails/mailers/user_mailer/password_reset我得到

我究竟做错了什么?
您正在调用 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
Run Code Online (Sandbox Code Playgroud)
或者将您的呼叫调整为UserMailer.password_reset 没有用户。
| 归档时间: |
|
| 查看次数: |
1976 次 |
| 最近记录: |