Managing options for select boxes

When having a select box like:

Select profession:

  • Unemployed
  • Hooligan
  • Canoo

I’ve on some occasions used a “type” class:

class ProfessionType < BaseType
@types = {}
@types[0] =‘Unemployed’)
@types[1] =‘Hooligan’)
@types[2] =‘Canoo’)

Where BaseType facilitates some convenience methods (allowing for eg.
ProfessionType.HOOLIGAN which returns 1, or returning an array
appropriate for generating the options for a select).

This approach works fine, but doesn’t feel quite right. An alternative
approach could be to just hard code the select box and save the string
values directly in the DB. Or one could make a “selectables” table in
the DB and model it like:

Selectable < AR::Base
#… convenience methods here …
def options_for_select

ProfessionSelectable < Selectable

But this is probably overdoing it, especially if the options are

I’m curious to know how others treat their options for selects - so
what do you do?



There is no golden hammer.
For some fix things I use the method in helper and for some dynamic
things usually data is stored in Db somewhere and I think that I have
one using data from yaml file.
So use as you see fit.