How to render 1="User" 2="Moderator" 3="Admin" etc.

Am in the midst of creating a largish app & have suddenly got struck
with brain freeze. I want to store an integral value in table, but
render it in HTML as text. So if the value is 1 I'd display the word
"User" in a listbox; if it's 2 I'd display it as "Moderator", etc.
That way later if I want to change the word "Moderator" to "Helper" or
whatever the numeric representation would not change, but the way it
appears would.

Can someone at the very least a) tell me what it's called when one
wants to render an enumerated value as something other than the number
so I can look it up, or b) point me at some sample code or even API
docs? Because I can't think of what this is called I don't know what
to search for! One too many all-nighters...

TIA

One way I do it is to override the attribute accessor to return the
enumerated value:

in your model (assuming the column is called usertype):

`@@usertypes = %w[User Moderator]

def usertype

@@usertypes[self[:usertype].to_i]

end`

There may be other ways, but this works well for me.

wrote: