Archive for the ‘DRY’ category

Fun with Rails Constantize

December 1, 2007

Visualization DiagramHave you ever found yourself working on a Rails project where you need certain behavior in a model based on type but STI[1] is not the right fit or you are already using STI and can not subtype again? I was working on a problem where a model utilized STI to create two types: Icon and Color. Within each type I had different data. Some of the data represented defaults for Icons or defaults for Colors and the others were specific. I’ve put together a little diagram on the right to illustrate this[2].

The way we had modeled the data made it very easy to pick out the specific icon or color theme (using an ActiveRecord finder for that type). However, based on the data instance returned by find I wanted to execute a series of methods to populate other models with data relevant to the Icon or Color instance. (more…)

Advertisements

How-To Make a Rails Partial With Optional Locals (Parameters)

August 25, 2007

Sorry, this article has moved!

http://hackd.thrivesmarthq.com/how-to-make-a-rails-partial-with-optional-locals-parameters