Вызов alias_method из ActionController, NoMethodError - PullRequest
0 голосов
/ 23 октября 2010

В Rails 3 я пытаюсь вызвать alias_method из моего before_filter, но я получаю эту ошибку: NoMethodError in MyController#index

class ApplicationController < ActionController::Base

  before_filter :my_test

  protect_from_forgery
  helper :all

  def my_test
      debugger
      alias_method :new_method_name, :old_method_name
  end
end

Из отладчика:

(rdb:3) p self.methods.grep /old_method_name/
["old_method_name"]

1 Ответ

0 голосов
/ 23 октября 2010

Вот ответ.Будь это хорошая идея или нет, я хотел бы услышать, что вы хотите сказать ...

class ApplicationController < ActionController::Base

  before_filter :my_test

  protect_from_forgery
  helper :all

  def my_test
      self.class_eval("alias_method :new_method_name, :old_method_name")
  end
end
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...