Ruby on rails 从ActionController、NoMethodError调用alias_方法
在Rails 3中,我试图在筛选之前从我的Ruby on rails 从ActionController、NoMethodError调用alias_方法,ruby-on-rails,ruby-on-rails-3,Ruby On Rails,Ruby On Rails 3,在Rails 3中,我试图在筛选之前从我的调用alias\u方法,但我得到了这个错误:MyController中的NoMethodError\index class ApplicationController < ActionController::Base before_filter :my_test protect_from_forgery helper :all def my_test debugger alias_method :new
调用alias\u方法
,但我得到了这个错误:MyController中的NoMethodError\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
答案是这样的。不管这是不是一个好主意,我想听听你有什么要说的
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
class ApplicationController
不管是谁拒绝了这个问题,请解释一下你为什么这样做。你必须向我们提供更多的信息,而不仅仅是一条错误消息。您正在使用的代码将是一个很好的开始。
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