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

前端 未结 4 1332
眼角桃花
眼角桃花 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 18:00

    @George Schreiber's method doesn't work as of Rails 3.1; the code has changed significantly.

    However, there's now an even better way to disable this feature in Rails 3.1 (and hopefully later). In your config/application.rb, add this line:

    config.action_controller.include_all_helpers = false
    

    This will prevent ApplicationController from loading all of the helpers.

    (For anyone who is interested, here's the pull request where the feature was created.)

提交回复
热议问题