Gareth Burrows
Gareth Burrows

Reputation: 1182

pass a ruby model attribute into a hash and return the value

I have a hash of marital statuses, which looks like this...

marital_hash = {"Unknown" => "U", "Married" => "M", "Single" => "S", "Widowed" => "W", "Divorced" => "D", "Separated" => "S", "Civil Partner" => "C"}

Then I have a user model, which has an attribute of :marital_status. The values of the marital_status are identical to the keys in the hash. How do I call the value of the hash for each employee based on their :marital_status?

Upvotes: 0

Views: 35

Answers (1)

Armin
Armin

Reputation: 1150

marital_hash[user.marital_status] should give you the appropriate value on the hash.

Upvotes: 1

Related Questions