Around filters in edge rails

Edge Rails currently has a bug / misfeature regarding around filters
which don't yield, the intention is to support cases like this:

around_filter :authorization_required

def authorization_required
  if logged_in?
    yield
  else
    redirect_to authentication_url
  end
end

I personally use this idiom, but I'm interested in hearing from anyone
else who does, and what issues they've struck with the current
edge-filters.

Can I ask, without sounding like a *complete* idiot, what the intent
of the yield statement would be in this scenario? My understanding of
around_filter is to run some code both before and after every action.
There's already a defined sequence of events going on -- so what would
one be yielding *to* ?

For example, in a before_filter, if I want "normal processing" to
occur, I just make sure I don't return false from my filter method. I
don't have to explicitly "yield" back to keep the ball moving.

Obviously the intent here is for something more interesting - can you
say a word or two about it?

Thanks!
Jeff
(feel free to continue this on rails-talk instead, if that's more
appropriate)

Around filters are like a wrapper for your action, where 'yield' is
the action. This is one of the reasons we all love ruby, and why
rails would be really hard to implement in other languages.

If you don't yield it's just like a before filter returning false. Very handy.

AFAIK you should usually use around filters instead of before-filters
so you can clear whatever instance variables you just set (so that
they don't have the potential of leaking between requests in
production mode).

I use that idiom, and I haven't upgraded to edge rails yet.

Courtenay

Can I ask, without sounding like a *complete* idiot, what the intent
of the yield statement would be in this scenario? My understanding of
around_filter is to run some code both before and after every action.
There's already a defined sequence of events going on -- so what would
one be yielding *to* ?

You're yielding to that 'defined sequence of events'. it lets you do
stuff like:

          ActiveRecord::Base.cache do
            yield
          end

(though rails does this for you now)

However I've found that it lets you make your larger before_filter /
after filters read much more nicely.

AFAIK you should usually use around filters instead of before-filters
so you can clear whatever instance variables you just set (so that
they don't have the potential of leaking between requests in
production mode).

Each request gets a new controller instance, so that's not accurate.

Thanks a lot, Koz. (And note to self: before asking, rtfm :slight_smile:

Jeff

AFAIK you should usually use around filters instead of before-filters
so you can clear whatever instance variables you just set (so that
they don't have the potential of leaking between requests in
production mode).

Each request gets a new controller instance, so that's not accurate.

Oh.. I think I meant @@class variables

courtenay