为什么所有时间都可以使用所有Rails帮助器?有没有办法禁用此功能? [英] Why are all Rails helpers available to all views, all the time? Is there a way to disable this?
问题描述
为什么我可以在其他控制器的视图中访问一个控制器的助手方法?有没有一种方法可以在不修改Rails的情况下禁用它?
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?
推荐答案
@George Schreiber的方法从Rails 3.1开始不起作用.代码已发生重大变化.
@George Schreiber's method doesn't work as of Rails 3.1; the code has changed significantly.
但是,现在有一种更好的方法可以在Rails 3.1中禁用该功能(希望以后再使用).在您的config/application.rb中,添加以下行:
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
这将阻止ApplicationController加载所有帮助程序.
(对于感兴趣的人,这是在其中创建功能的拉取请求 )
(For anyone who is interested, here's the pull request where the feature was created.)
这篇关于为什么所有时间都可以使用所有Rails帮助器?有没有办法禁用此功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!