I’ve implemented the Sortable.js in my view to sort some list elements. After sort the list is correctly updated in the db based on the layout in the browser.
def update_array_order(ids)
self.object_assets.update_all(['ordinal = FIND_IN_SET(id, ?)', ids.join(',')])
end
Fine. The above method get passed an JS array of integers(ids). I’m not including JS or controller code because I don’t feel it’s important.
However my lists are paginated and if you aren’t viewing the complete list at time of sort, the records that aren’t present get converted to 0 in the db. I would like it to leave the ids that aren’t present alone (as it wouldn’t screw up the overall ordering). With Rails 4 they’ve taken the condition out of update_all, so I need to create a where clause, so I repeated the FIND_IN_SET with a != NULL… It’s not working.
Wondering if anyone has had the need for a condition with update_all while using Rails 4 and what you did.
Thanks