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

前端 未结 4 1333
眼角桃花
眼角桃花 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:51

    Actually in Rails 2, the default functionality of ActionController::Base was to include all helpers.

    Changeset 6222 on 02/24/07 20:33:47 (3 years ago) by dhh: Make it a default assumption that you want all helpers, all the time (yeah, yeah)

    change:

    class ApplicationController < ActionController::Base 
      helper :all # include all helpers, all the time 
    end 
    

    As of Rails 3 beta 1, that is no longer the case as noted in the CHANGELOG:

    • Added that ActionController::Base now does helper :all instead of relying on the default ApplicationController in Rails to do it [DHH]

提交回复
热议问题