Nhan Nguyen
Nhan Nguyen

Reputation: 33

Overriding devise recoverable

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?

Upvotes: 0

Views: 1331

Answers (1)

Denny Mueller
Denny Mueller

Reputation: 3615

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

Upvotes: 1

Related Questions