September 18th, 2007

ActionPack: Filter types

Using an external class makes for more easily reused generic filters, such as output compression. External filter classes are implemented by having a static filter method on any class and then passing this class to the filter method. Example:

class OutputCompressionFilter
def self.filter(controller)
controller.response.body = compress(controller.response.body)
end
end

class NewspaperController < ActionController::Base
after_filter OutputCompressionFilter
end

The filter method is passed the controller instance and is hence granted access to all aspects of the controller and can manipulate them as it sees fit.

Aside
Ruby on Rails
coding

Comments (0)

Permalink

RSpec Presentation

This is a zip of my RSpec presentation from Desert Code Camp this past weekend.

It includes all of my slides in the PDF, plus all of the supporting code.

Enjoy!

RSpec
Ruby on Rails
Technology
coding
desertcodecamp

Comments (0)

Permalink