Create field with condition while looping through an array in ruby

I had a problem with something else, thank you