Modify *_filter methods to allow stacking of declarations?

Hey guys,

I’d like to hear people’s opinions on modifying the filter class methods such that we could stack declarations. Take the following setup as an example:

class DashboardController < ApplicationController
include Filters
include RssPresenter
before_filter :get_user, :only => [:index]

def some_action_that_doesnt_require_user
end
end

module Filters
def get_user
@user = User.find(params[:id])
end

private :get_user
end

module RssPresenter
def self.included(base)
base.before_filter :get_user, :only => [:rss]
end

def rss
#stuff
end
end

Currently, get_user will not be called on RssPresenter#rss because the before_filter call in DashboardController overrides the base.before_filter in RssPresenter. Rewriting RssPresenter like this:

module RssPresenter
def self.included(base)
base.before_filter :get_user
end

def rss
#stuff
end
end

will not work because then get_user will get called on every action in DashboardController.

Let me know what you guys think of this, and I’ll work on a patch if you’d like.

Thanks,
Ryan

Should probably clarify what I’m actually proposing :slight_smile:

I’d like it to look like this:

class DashboardController < ApplicationController
include Filters
include RssPresenter
before_filter :get_user, :on => [:index]

def some_action_that_doesnt_require_user

end
end

module Filters
def get_user

@user = User.find(params[:id])

end

private :get_user
end

module RssPresenter
def self.included(base)
base.before_filter :get_user, :on => [:rss]
end

def rss
#stuff
end
end

Where specifying an :on parameter would add actions to the action list for the given filter method.