I did recommend this, but I also agree, that the proposal of @0robustus1 is more ruby (whereas the current solution looks a little javascripty).