0

サブクラス化しています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
 */
4

2 に答える 2

0

私はDevise 2.1.2とリンクを使用していることがわかりました: https://github.com/plataformatec/devise/blob/master/app/controllers/devise/passwords_controller.rb

最新バージョンのDevise用です。

于 2013-10-02T21:45:36.623 に答える