0

I have a module included in one of my models. being specific in my user model database_authenticatable is included.

devise  :database_authenticatable

The module has a method valid_password?(password) I want to overwrite the method as follow

def valid_password?(password)
  if my_condition_is_true
    do_something_new()
  else
    # do  what valid_password(password) always does
  end
end

in my else I'm thinking of copying whatever is defined insdide of valid_password() in database_authenticatable.rb module, but i'm wondering if there is a way to just tell it to do that? like in inheritance I can do super?

Also I realized no mether what, after calling my valid_password method, it cals the module valid_password method, any idea how to avoid this?

Matilda
  • 1,708
  • 3
  • 25
  • 33

1 Answers1

1

You could write your modification as a module and include it so it's loaded similarly to how the module with the previous method was loaded. If you can do this you should be able to call super correctly.

Have a look at this thread for some ideas (it'll depend on how the rest of your code looks, of course): Rails 3: alias_method_chain still used?

Community
  • 1
  • 1
James Brooks
  • 658
  • 4
  • 5