Replace map.flatten with flat_map in railties