You should call ui_params_for_form once and store it in a local variable, and then check size and iterate, otherwise the hash is built twice here.