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

前端 未结 4 1341
眼角桃花
眼角桃花 2020-11-29 17:22

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条回答
  •  囚心锁ツ
    2020-11-29 17:58

    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.

提交回复
热议问题