English 中文(简体)
铁路 3. 控制器的惯性警报方法
原标题:Rails 3. Inheritance callback method in the controller

我有2名控制员。

OauthController and Admin:OauthController. Admin:OauthController从主计长办公室继承。

主计长办公室采用公开的“召回”方法。

Admin:OauthController looks:

class Admin::OauthController < OauthController
end

然后,我谈一下“行政/面簿_oauth/questback”的链接植被错误

Unknown action
The action  callback  could not be found for Admin::OauthController

But if I add callback method with call super in Admin::OauthController all works.

class Admin::OauthController < OauthController    
  def callback
    super
  end
end

这种行为出现在向铁路运输3号之后。 其他方法由主计长办公室继承,没有问题。

问题回答

如果我们在“行动——方法”清单中不采取预期行动,就会提出错误的“行动指示”。

<>AbstractController:Base#internal_methods

# A list of method names that should be considered actions. This
# includes all public instance methods on a controller, less
# any internal methods (see #internal_methods), adding back in
# any methods that are internal, but still exist on the class
# itself. Finally, #hidden_actions are removed.
#
# ==== Returns
# * <tt>array</tt> - A list of all methods that should be considered actions.
def action_methods
  @action_methods ||= begin
    # All public instance methods of this class, including ancestors
    methods = public_instance_methods(true).map { |m| m.to_s }.to_set -
      # Except for public instance methods of Base and its ancestors
      internal_methods.map { |m| m.to_s } +
      # Be sure to include shadowed public instance methods of this class
      public_instance_methods(false).map { |m| m.to_s } -
      # And always exclude explicitly hidden actions
      hidden_actions

    # Clear out AS callback method pollution
    methods.reject { |method| method =~ /_one_time_conditions/ }
  end
end

www.un.org/Depts/DGACM/index_spanish.htm 不要列入最后清单“AbstractController:Base#internal_methods”。

 # A list of all internal methods for a controller. This finds the first
  # abstract superclass of a controller, and gets a list of all public
  # instance methods on that abstract class. Public instance methods of
  # a controller would normally be considered action methods, so methods
  # declared on abstract classes are being removed.
  # (ActionController::Metal and ActionController::Base are defined as abstract)
  def internal_methods
    controller = self
    controller = controller.superclass until controller.abstract?
    controller.public_instance_methods(true)
  end

www.un.org/Depts/DGACM/index_spanish.htm 最后,最令人感兴趣的是:。

>> ActionController::Base.instance_methods.include?( callback )
=> true




相关问题
Subclass check, is operator or enum check

A couple of friends was discussing the use of inheritance and how to check if a subclass is of a specific type and we decided to post it here on Stack. The debate was about if you should implement a ...

C++ Class Inheritance problem

Hi I have two classes, one called Instruction, one called LDI which inherits from instruction class. class Instruction{ protected: string name; int value; public: Instruction(string ...

Overloading a method in a subclass in C++

Suppose I have some code like this: class Base { public: virtual int Foo(int) = 0; }; class Derived : public Base { public: int Foo(int); virtual double Foo(double) = 0; }; ...

Embedding instead of inheritance in Go

What is your opinion of this design decision? What advantages does it have and what disadvantages? Links: Embedding description

Extending Flex FileReference class to contain another property

I want to extend the FileReference class of Flex to contain a custom property. I want to do this because AS3 doesn t let me pass arguments to functions through event listeners, which makes me feel sad,...

Interface Inheritance in C++

I have the following class structure: class InterfaceA { virtual void methodA =0; } class ClassA : public InterfaceA { void methodA(); } class InterfaceB : public InterfaceA { virtual ...

热门标签