在Rails Devise gem中,如何修改send_reset_password_instructions方法? [英] In Rails Devise gem how to modify the send_reset_password_instructions method?

查看:149
本文介绍了在Rails Devise gem中,如何修改send_reset_password_instructions方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想修改 send_reset_password_instructions 方法,以便可以通过它向URL发送一些额外的参数。然后,我可以在url中读取该参数,如果它存在,我将以不同的方式设置视图(和邮件程序)的样式。

I want to modify the send_reset_password_instructions method so that I can send some extra parameters through it to the url. Then I can read that parameter in the url and if its present I will style the view (and the mailer) in a different way.

我真正需要做的是发送重置密码而不是确认电子邮件。我已经让我的应用发送重置密码而不是发送确认密码,但是现在我需要编辑邮件程序和视图,以使其与众不同。我该怎么办?

What I really need to do is send the reset password instead of confirmation email. I have already made my app send the reset password instead of confirmation but now I need to edit the mailer and the view to be different. How can I do this?

推荐答案

好的,所以您的问题分为两部分。

OK so your question has 2 parts.


  • 覆盖 send_reset_password_instructions 方法:


  1. 访问 Devise Github页面,并找到方法的定义位置。

  2. 在您自己的应用文件夹中创建一个具有相同名称和相对路径的文件。例如:Devise有此助手 app / mailers / devise / mailer.rb ,如果要覆盖它,可以在自己的 app中创建相同的助手目录。

  3. 复制方法并根据需要覆盖。 Devise将自动提取文件。

  1. Visit the Devise Github page and find where the method is defined.
  2. Create a file with the same name and relative path in you own app folder. Eg.: Devise has this helper app/mailers/devise/mailer.rb, if you want to override it you create the same in you own app directory.
  3. Copy the method and override as needed. Devise will automatically pickup the files.


  • 编辑视图/邮件:您只需要运行以下命令:

  • Editing the views / mailers: You just need to run this command:

    轨道生成devise:views

    您将在您的views文件夹中查看邮件视图。

    You will have the mailer views in you views folder.

    希望这会有所帮助:)

    这篇关于在Rails Devise gem中,如何修改send_reset_password_instructions方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆