我正在子类化Devise::PasswordsController
https://github.com/plataformatec/devise/blob/master/app/controllers/devise/passwords_controller.rb
class MyPasswordsController < Devise::PasswordsController
protected
# Reference: https://github.com/plataformatec/devise/blob/master/app/controllers/devise/passwords_controller.rb
def unlockable?(resource)
v = resource.respond_to?(:unlock_access!) &&
resource.respond_to?(:unlock_strategy_enabled?)
# && resource.unlock_strategy_enabled?(:none) # sets to :none
puts "##############################"
puts v
puts "##############################"
return v
end
end
我也有路线:
devise_for :users, :controllers => {:passwords => :my_passwords}
我确定这Devise::PasswordsController::update
被调用了,但是为什么 ruby 不选择我的MyPasswordsController::unlockable?
方法(它应该在update
方法中调用?
编辑
我想说的是 C++ 中的以下代码。Ruby 的行为是否有所不同?
#include <iostream>
using namespace std;
class Base
{
public:
virtual void VirtualMethod()
{
cout << "Base::VirtualMethod" << endl;
VirtualMethodSub();
}
virtual void VirtualMethodSub()
{
cout << "Base::VirtualMethodSub" << endl;
}
};
class Dervied : public Base
{
virtual void VirtualMethodSub()
{
cout << "Derived::VirtualMethodSub" << endl;
}
};
int main()
{
Dervied d;
d.VirtualMethod();
return 0;
}
/* Output:
Base::VirtualMethod
Derived::VirtualMethodSub
*/