Monthly Archives: December 2008

Passing a parameter to a before filter

Creating a controller filter that accepts a parameter is less than obvious as I found today while trying to add more than basic authentication to a controller.

Turns out that you need to do it like this :

before_filter :only => [:create, :update, :destroy] do |controller|
controller.filter_function(parameter)
end

rather than allowing a parameters array to pass into the before_filter function which would be nice.