Skip to content

Instantly share code, notes, and snippets.

@BigMcLargeHuge
Created July 26, 2019 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BigMcLargeHuge/b65f589c510b5bca1c5f184992af21d0 to your computer and use it in GitHub Desktop.
Save BigMcLargeHuge/b65f589c510b5bca1c5f184992af21d0 to your computer and use it in GitHub Desktop.
bigUpdate
#Looking for the best way to update items in a table in mass below is the best I've come up with but it seems hacky and I've read that update() is depreciated
class Table < ActiveRecord::Base
...
class << self
def big_update
items = Table.all
saves=[]
items.each do |item|
item.value = rand(10)
saves << item.as_json
end
saves = Hash[*saves.map{ |p| [p["id"], p] }.flatten]
self.update(saves.keys, saves.values)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment