gmosx.ninja

Ruby idiom to fill enumerated Og managed attributes

Quite often my Og managed objects (Entities) include an attribute that takes enumerated values. I use the following code snippet to augment Nitro's form generation helper to render a usable control.

TYPE_VALUES = Dictionary[
    TEXT = 0, 'Article',
    IMAGE = 1, 'Image',
    VIDEO = 2, 'Video'
]

attr_accessor :type, Fixnum, :control => :options, :options_data => TYPE_VALUES

This code uses the Dictionary class from the Facets library. I hope you will find this useful as well ;-)