views:

27

answers:

1

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 :all

  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"]
A: 

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
Dex