Skip to content

Instantly share code, notes, and snippets.

View bspaulding's full-sized avatar

Bradley Spaulding bspaulding

View GitHub Profile
@bspaulding
bspaulding / application_controller.rb
Created October 11, 2011 14:51 — forked from ajvargo/gist:1277150
Create a presenter object on the fly in Rails
# Inspired by Ryan Bates pro RailsCast "Presenters from Scratch"
# This is a proof of concept for 'automagically' creating presenter objects
#
# This assumes you have presenter objects that follow the convention
# Object => ObjectPresenter
#
# It intercepts the 'render' method in the controller, and does some
# introspection to see if there is a presenter defined for the class
# of the instance variable being looked at. If so, it makes a presenter
# and adds it as an instance variable