Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 从ActionController、NoMethodError调用alias_方法_Ruby On Rails_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails 从ActionController、NoMethodError调用alias_方法

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

在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_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