从ActionController调用alias_method,NoMethodError

时间:2010-10-22 22:48:56

标签: ruby-on-rails ruby-on-rails-3

在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 :(得分:-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