开发者

Calling alias_method from an ActionController, NoMethodError

开发者 https://www.devze.com 2023-01-21 05:28 出处:网络
In Rails 3 I\'m trying to call alias_method from my before_filter but I\'m getting this error: NoMethodError in MyController#index

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
0

精彩评论

暂无评论...
验证码 换一张
取 消