开发者

FInding out which before_filters are already set in Rails 3

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?


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 >
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜