Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 850
Steffen Avatar asked Sep 29 '10 11:09

Steffen


1 Answers

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 >
like image 188
Noam Ben Ari Avatar answered Nov 10 '22 18:11

Noam Ben Ari