(Not) Helpful Helpers

Posted by Matt Williams

In Rails 2.0.x, application.rb has a:

1
2

helper :all
which has the effect of including all the helpers. In general, this is helpful. However, if you want to have different behaviour in different controllers, this can cause problems, because only one behaviour will be available for all controllers. And the behaviour seems linked to the default load order (alphabetical) -- that said, if you have two controllers FooController and BarController, then the helpers will be loaded in the following order:
  1. ApplicationHelper
  2. BarHelper
  3. FooHelper

So, if you expect to have different behaviours in Foo and Bar, you'll be disappointed. The behaviours override each other, leaving a single behaviour across the application. In order to fix this, remove or comment out the declaration in application.rb.

Comments

Leave a response