2010-10-22 18 views
0

在Rails 3我想打電話給alias_method從我before_filter但我得到這個錯誤:NoMethodError in MyController#index從ActionController的調用alias_method,NoMethodError

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

無論誰打開這個問題,請解釋你爲什麼這樣做。 – BeemerGuy 2010-10-22 23:04:20

+3

您將不得不向我們提供更多信息,而不僅僅是一條錯誤消息。您使用的代碼將是一個很好的開始。 – 2010-10-22 23:04:29

回答

-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 
+0

無論誰低估了這一點,請提供一個更好的選擇。 – Dex 2011-09-06 04:53:33

相關問題