Proper storage of "enumeration" models in Rails -


apologies if question little imprecise, i'll describe problem below.

i'm setting models in rails project, , 1 thing i've noticed i'm running more few times dealing attributes meet following criteria:

  • they can set 1 of small, predefined set of values
  • those values need have both name , identifier (whether numeric id, code, whatever)
  • the values ever change result of deal of code change.

for example, 1 of models should have status field can set 1 of: defining, executed, or completed. need show specific words within interface, don't want store strings in db in case need change them in future (or internationalize, or whatever.)

the obvious option define models each of these models, seems present deal of overhead in maintaining models, ensuring write migrations between environments, etc. each 1 of these, seems lot of overhead.

the other option store integer, , whip "enumeration" type class stores translation of values - work fine, i'm concerned i'll lose associations , other handy stuff activerecord models.

any advice on best way handle situation?

check out ruby gem i've been working on called classy_enum. i'm pretty sure you're looking for. readme has example usage, premise lets define multiple enum members classes can have different properties.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -