# Numeric context of enum in Views

**URL:** <https://www.ruby-forum.com/t/numeric-context-of-enum-in-views/114525>\
**Category:** Rails\
**Created:** [September 13, 2007, 9:59pm UTC](https://www.ruby-forum.com/t/numeric-context-of-enum-in-views/114525 "2007-09-13T21:59:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sgudibanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@sgudibanda](https://www.ruby-forum.com/u/sgudibanda)\
**Post date:** [September 13, 2007, 9:59pm UTC](https://www.ruby-forum.com/t/numeric-context-of-enum-in-views/114525/1 "2007-09-13T21:59:37Z")

</div>

Hi,

I have a select list of this fashion: edit\_patient.rhtml

\<%= select ‘patient’, ‘status’, [[‘Unspecified’,1], [‘Researhing’,2],  
[‘Critical’,3],  
[‘Normal’,4],  
[‘Needs extra person’,5],  
%\>

I have enums defined in the database(mysql) for status. Storage is fine.  
But on retrieval, it is always show it as Unspecified . But if i just  
display status , i am getting the right string. I realized this was  
happening , because returned value for status is string and hence  
Selected option is of 0.

Now how do i force the retrieval to numeric context ?  
forcing numeric context like status+0 doesn’t work in rails ☹

Any suggestions?

Sandeep G

---

<div class="post-metadata">

**Author:** ![sgudibanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@sgudibanda](https://www.ruby-forum.com/u/sgudibanda)\
**Post date:** [September 17, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/numeric-context-of-enum-in-views/114525/2 "2007-09-17T13:24:01Z")

</div>

I think you are looking for attributes\_before\_type\_cast. See

> **[ActiveRecord::Base](https://api.rubyonrails.org/classes/ActiveRecord/Base.html#M001057)**
>
> Active Record Active Record objects don't specify their attributes directly, but rather infer them from the table definition with which they're linked.

Sandeep G. wrote:

> I have enums defined in the database(mysql) for status. Storage is fine.  
> Sandeep G

–  
Sincerely,

William P.
