为什么仍然可以在视图中访问私有帮助器方法? [英] Why can private helper methods still be accessed in views?

查看:60
本文介绍了为什么仍然可以在视图中访问私有帮助器方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

另一个为什么会这样"的问题:我注意到,仍然可以在视图中访问私有帮助器方法.为什么?并且有一种方法可以防止这种情况发生(例如,在具有只能从另一个帮助程序内部调用的帮助程序方法时)?

Just another "why is it that way" question: I noticed that private helper methods still can be accessed within views. Why's that? And is there a way to prevent this (e.g. when having helper methods that should only be called from within another helper)?

推荐答案

帮助器是模块混入视图中.这意味着帮助程序中的公共方法,受保护方法和私有方法将成为视图上的公共方法,受保护方法和私有方法.

Helpers are modules that get mixed in to the views. This means that public, protected and private methods in the helper become public, protected and private methods on the views.

我认为您实际上无法从视图中隐藏帮助程序方法.您需要执行类似的操作,例如在您的帮助器中实例化一个帮助器类,然后委派该调用器的类-听起来它可能很快变得混乱. :)

I don't think that you can actually hide the helper methods from the view. You'd need to do something like have a helper class which you instantiate in the helper and then delegate calls to that - sounds like it could get messy fast though. :)

这篇关于为什么仍然可以在视图中访问私有帮助器方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆