diff options
Diffstat (limited to 'helpers.rb')
-rw-r--r-- | helpers.rb | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -106,13 +106,14 @@ helpers do collection = JSON.parse(json) objects.each do |object| id = object['id'] || object - if action == 'add' + if action == 'delete' collection['orderedItems'].delete_if { |o| o['id'] == id or o == id } - elsif action == 'delete' + elsif action == 'add' ids = collection['orderedItems'].collect { |i| i['id'] } collection['orderedItems'] << object unless ids.include?(id) or collection['orderedItems'].include?(id) end end + collection['orderedItems'].uniq! collection['totalItems'] = collection['orderedItems'].size f.rewind f.puts collection.to_json |