Close
Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

PIVOTAL LABS
SF Standup 8/12/2011: Helpers All The Way Down

Ask for Help

clear_helpers and ActionController::Base”

A [recent?] change to Rails 3 moved helper :all from the default ApplicationController to ActionController::Base — which would be fine, except that there’s little documentation on how to override this (for example, when you don’t want all helpers included in your controller class)

There is a lesser known method from AbstractController::Helpers

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

You would think that since helper :all is being called from the base class, there would be no way to override it. Except for this little bit of code at the bottom of ActionController::Base:

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

So, clear_helpers will “work” for all subclasses of ApplicationController — which is everything you should care about. And the default, all helpers included, remains.

Comments
Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *