clear_helpers is your new friend...
going down the painful way of upgrading your app from rails 2.x to rails3? one of the gotchas can be that suddenly you find B helper's X method running when you normally expect A helper's X method to run...

The dog is buried in ActionController::Base (the parent class of your ApplicationController class).
in The reason for this lies in In Rails 3:actionpack/actioncontroller/base.rb (around line 224)


def self.inherited(klass) super klass.helper :all if klass.superclass == ActionController::Base end

Since you usually derive your ApplicationController from ActionController::Base, all helpers will be included by default.

To come around this, call ‘clear_helpers’ (AbstractClass::Helpers; included in ActionController::Base) at the beginning of your controller’s code.

clear_helpers clears up all existing helpers in this class, only keeping the helper with the same name as this class.

Eg.:


class ApplicationController < ActionController::Base
  clear_helpers
  ...
  # your existing code
  ...
end

1 comments
4de0d5f0a9702b106dd651027dc425c6 dae   Wed, 29 Jun 2011 04:48:04 +0000
Thanks so much for this answer. I was looking like 5 days
New Comment







mini_captcha.png