Why are all Rails helpers available to all views, all the time? Is there a way to disable this?

Viewed 38100

Why can I access helper methods for one controller in the views for a different controller? Is there a way to disable this without hacking/patching Rails?

4 Answers

The answer depends on the Rails version.

Rails >= 3.1

Change the include_all_helpers config to false in any environment where you want to apply the configuration. If you want the config to apply to all environments, change it in application.rb.

config.action_controller.include_all_helpers = false

When false, it will skip the inclusion.

Rails < 3.1

Delete the following line from ApplicationController

helper :all

In this way each controller will load its own helpers.

Related