Numeric context of enum in Views

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

Any suggestions?

Sandeep G

I think you are looking for attributes_before_type_cast. See
http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M001057

Sandeep G. wrote:

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


Sincerely,

William P.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs