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

**URL:** <https://www.ruby-forum.com/t/how-to-render-1-user-2-moderator-3-admin-etc/117870>\
**Category:** Rails\
**Created:** [October 21, 2007, 10:20pm UTC](https://www.ruby-forum.com/t/how-to-render-1-user-2-moderator-3-admin-etc/117870 "2007-10-21T22:20:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 21, 2007, 10:20pm UTC](https://www.ruby-forum.com/t/how-to-render-1-user-2-moderator-3-admin-etc/117870/1 "2007-10-21T22:20:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 21, 2007, 10:32pm UTC](https://www.ruby-forum.com/t/how-to-render-1-user-2-moderator-3-admin-etc/117870/2 "2007-10-21T22:32:28Z")

</div>

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.

removed\_email\_address@domain.invalid wrote:

> 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
> 
> >

–

Sincerely,

William P.
