Rails 3. Метод обратного вызова наследования в контроллере - PullRequest
0 голосов
/ 17 октября 2011

у меня 2 контроллера

OauthController и Admin :: OauthController. Когда Admin :: OauthController унаследован от OauthController.

В OauthController реализован метод «обратный вызов», который является общедоступным.

Admin :: OauthController выглядит так:

class Admin::OauthController < OauthController
end

Тогда, если я пойду по ссылке "/ admin / facebook_oauth / callback" получим ошибку

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

Но если я добавлю метод 'callback' с вызовом super в Admin :: OauthController, все будет работать.

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

Это поведение появляется после перехода на Rails 3. Другие методы наследуются OauthController без проблем.

1 Ответ

0 голосов
/ 18 октября 2011

Ошибка «повысить ActionNotFound» возникает, если у нас нет нужного действия в списке «action_methods»

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

Не попадать в окончательный список "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

И, наконец, самое интересное:

>> ActionController::Base.instance_methods.include?('callback')
=> true
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...