It is not a good pratice to use render :update like that. When the RJS
is more than a one-liner, say, it is more clean to extract that to its
own RJS template. Because RJS belongs to the V in MVC.
On the other hand the idea of the loop + calls to page...something is
correct. In your example the ID of the element is always the same
though. Knowing this, you could for example simplify the code like
eliminating the conditional to get a wrong but working version, and
after that add all the logic.