How to display value from Hash onto page
I have a hash in my User model class
GENDERS = {'1' => 'Male', '2' => 'Female', '3' => 'Secret'}
And i store the key for every user.
So when user read their info, i want to display corresponding value regarding to the key
So i am doing like this:
<td><%= User::GENDERS[@user.gender] %></td>
But i cannot see anything display.
if i do the following,i do see the right key display
<td><%= @user.gender %></td>
So, what is the right way to display a value from a hash onto page programatically?
Thanks.
Is the gender field a string or an integer? If it’s an integer, you’ll need to change the hash to: