Overriding devise recoverable

旧街凉风 提交于 2020-02-25 23:08:50

问题


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.

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?

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.

Can someone please help?

EDIT

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

Any idea about this?


回答1:


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


来源:https://stackoverflow.com/questions/51496050/overriding-devise-recoverable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!