Calling alias_method from an ActionController, NoMethodError
In Rails 3 I'm trying to call alias_method
from my before_filter
but I'm getting this error: NoMethodError in MyController#index
class ApplicationController < ActionController::Base
before_filter :my_test
protect_from_forgery
helper :a开发者_如何学运维ll
def my_test
debugger
alias_method :new_method_name, :old_method_name
end
end
From the debugger:
(rdb:3) p self.methods.grep /old_method_name/
["old_method_name"]
Here is the answer. Whether or not this a good idea or not, I'd like to hear what you have to say...
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
精彩评论