找出 Rails 3 中已经设置了哪些 before_filters

发布于 2024-09-25 12:55:27 字数 271 浏览 1 评论 0原文

我有一个用于控制器配置的 DSL。底层功能依赖于 before_filters。为了防止多次设置 before_filter,我确实需要查明是否已经在 Rails 3 控制器中设置了 before_filter。由于 before_filter 的工作方式与类变量不同(继承、类重新加载),我不能只设置一个类变量来检查。

深入研究 AbstractController 回调的新高度抽象代码并没有给我任何线索,告诉我这是否可能。

我真的需要为控制器中的每个DSL调用调用skip_filter吗?

I have a DSL for controller configuration. The underlying functionality relies on before_filters. To prevent setting the before_filter more than once, I really need to find out whether a before_filter is already set in a Rails 3 controller. Since before_filter work different from class variables (inheritance, class reloading), I cannot just set a class variable to check.

Digging through the new highly abstracted code for the AbstractController callbacks does not give any clue to me whether this is possible at all.

Do I really need to call skip_filter for every DSL call in the controller?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眉目亦如画i 2024-10-02 12:55:27

以下是我发现的一种方法:

noam$ rails c

Loading development environment (Rails 3.0.3)

ruby-1.9.2-p136 :001 > ApplicationController._process_action_callbacks.map {|c| c.filter if c.kind == :before}.compact
=> [:deny_banned_user, :validate_session, :verify_authenticity_token, :require_user_login]
ruby-1.9.2-p136 :002 >

Below is a way I found to do this:

noam$ rails c

Loading development environment (Rails 3.0.3)

ruby-1.9.2-p136 :001 > ApplicationController._process_action_callbacks.map {|c| c.filter if c.kind == :before}.compact
=> [:deny_banned_user, :validate_session, :verify_authenticity_token, :require_user_login]
ruby-1.9.2-p136 :002 >
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文