26 May 2009

Flexifields Rails Plugin Published on Github

I have recently published a Ruby on Rails plugin on Github. The requirement came about because I have been doing a lot of work with the Adva CMS rails application (look into the adva system at github). Adva uses engines to modularise the various CMS functional areas. Being a content management system, adva has a data model for Content and a sub-class of this for an Article. Articles or Content have three attributes that can store text each with an implicit label: title, body and excerpt. I needed more explicitly labelled attributes to store extra text for a 'flavor' of Article - take a Recipe as an example of a flavor of Article and let us say that a CMS admin wants to define extra attributes for prep_time, cooking_time and serves_portions so that a CMS editor can supply these extra texts outside of the main body of the recipe in a consistent way. Note that the names of these extra attributes are not known at design time so the data model can't be extended to include these attributes. I decided to write a plugin (well its turned out to be a mini-engine for rails 2.3 because I decided not to require the plugin user to use generators to copy the models and routes into the main rails app) that adds the ability to have extra attributes as a has_one association off of any model. Each flavor is modelled as a Flexifield Definition and each label for a given flavor is modelled as a Flexifield Definition Entry. Using this plugin I can have different flavors of Article that can store up to 16 differently labelled texts per Article record.

http://github.com/guyboertje/has_flexiblefields/tree/master

The next steps will be to look into using it in Adva. In adva the administrative routes/pages all point to files below an admin folder. So adding support for CRUD on the labels (called FlexifieldDefEntries) via the standard Adva admin forms will require a few folder and route changes.

Also, on the adva group and IRC, we debated whether it made more sense to create a separate engine for each flavor of Article - I argued that I was not modelling a Recipe or Car Review entity but an Article entity that is specialised, hence the extra attributes and not a new engine. It could also be argued that these flavors of Article require that certain common (to each flavor) bits of text are removed from needing to be (randomly placed) in the body and are stored separately.

No comments: