# Experimental plugin: Rack-based after\_filter-ish behavior

**URL:** <https://www.ruby-forum.com/t/experimental-plugin-rack-based-after-filter-ish-behavior/157416>\
**Category:** Rails\
**Created:** [January 11, 2009, 12:51am UTC](https://www.ruby-forum.com/t/experimental-plugin-rack-based-after-filter-ish-behavior/157416 "2009-01-11T00:51:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_ASBlack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b4bc9f/32.png) [@David\_ASBlack](https://www.ruby-forum.com/u/David_ASBlack)\
**Post date:** [January 11, 2009, 12:51am UTC](https://www.ruby-forum.com/t/experimental-plugin-rack-based-after-filter-ish-behavior/157416/1 "2009-01-11T00:51:09Z")

</div>

Hi –

I’ve been working on a per-action Rack-based after\_filter-like  
facility, and I thought others might like to see the experiment (and I  
do consider it experimental). It’s a plugin called after\_middles, at:

git://github.com/dblack/after\_middles.git

It works like this (assuming Rails 2.3/edge):

# Define something like this somewhere:

class MyRackApp  
def call(env)  
# you already have @app here for the  
# middleware chain  
do\_stuff…  
@app.call(env)  
end  
end

# Then in your controller:

class ThingsController \< ApplicationController  
after\_middle MyRackApp, :only =\> :show  
def show  
…  
end  
end

It maintains its own middleware stack, and after\_middle itself is just  
a wrapper around before\_filter that adds to that stack.

I’m not sure yet how useful it will be (either for adding  
functionality or for speed), except it’s already served one of its  
purposes, namely to help me learn more about the recent controller  
code and the implementation of the middleware integration. Anyway, if  
interested, have a look, and let me know if you have any  
comments.

David

–  
David A. Black / Ruby Power and Light, LLC  
Ruby/Rails consulting & training: [http://www.rubypal.com](http://www.rubypal.com)  
Coming in 2009: The Well-Grounded Rubyist ([The Well-Grounded Rubyist](http://manning.com/black2))

[http://www.wishsight.com](http://www.wishsight.com) =\> Independent, social wishlist management!
