覆盖设计可恢复 [英] Overriding devise recoverable

查看:26
本文介绍了覆盖设计可恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我的声誉低于 50,所以我无法在此帖子中接受的答案下方发表评论 在 Rails Devise gem 中如何修改 send_reset_password_instructions 方法? 了解更多信息.

As my reputation is lower than 50, so Im not able to comment below the accepted answer in this post In Rails Devise gem how to modify the send_reset_password_instructions method? for more information.

我想在设计中自定义recoverable.rb.我在我的文件夹中复制了它的路径 lib/devise/models/recoverable.rb.问题是当请求发送重置密码指令时,我收到错误 undefined method activerecord51?对于设计:模块.我该如何解决这个问题?

I want to customize recoverable.rb in devise. I made a copy of it in my folder with path lib/devise/models/recoverable.rb. The problem is when request to send reset password instruction, I got error undefined method activerecord51? for Devise:Module. How do i solve this?

看来我的可恢复不在设计模块中.我尝试在 lib/ 文件夹中复制 devise.rb 的副本.但这无济于事.

It seems my recoverable is not in Devise module. I tried a bit by making a copy of devise.rb in lib/ folder. But it doesn't help.

有人可以帮忙吗?

编辑

很抱歉给您带来不便.目前,我只是想将更多选项传递给 send_reset_password_instructions 方法.

Sorry for any inconvenience. At the moment Im just trying to pass more opts to the method send_reset_password_instructions.

对此有什么想法吗?

推荐答案

在一些 Rails 初始化程序中如何做?您可能会覆盖原始类/模块,因此所有其他方法都消失了.

How about do it in some rails initializer? Your are possibly overwriting the original class/module so all the other methods are gone.

# config/initalizers/devise.rb
Devise::Models::Recoverable::ClassMethods.module_eval do
  def send_reset_password_instructions(your, params)
    token = set_reset_password_token
    send_reset_password_instructions_notification(token)

    token
  end
end

这篇关于覆盖设计可恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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