How to get key from value ruby on rails hash or array

    To get key from value you can use below code:
    testhash = {:active => 1, :blocked => 2, :pending => 3}

    testhash.map{ |k,v| v==2 ? k.to_s.capitalize!  : nil }.compact

    It will display result "Blocked"
    5
    Average: 5 (1 vote)