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] = ProfessionValue.new('Unemployed') @types[1] = ProfessionValue.new('Hooligan') @types[2] = ProfessionValue.new('Canoo') end
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 #... end end
ProfessionSelectable < Selectable end
But this is probably overdoing it, especially if the options are fixed.
I'm curious to know how others treat their options for selects - so what do you do?
Thanks.
Morten