在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"]
答案 0 :(得分:-1)
这是答案。不管这是不是一个好主意,我想听听你说的话......
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