Skip to content

Instantly share code, notes, and snippets.

@wheeyls
Created January 3, 2013 18:53
Show Gist options
  • Save wheeyls/4445927 to your computer and use it in GitHub Desktop.
Save wheeyls/4445927 to your computer and use it in GitHub Desktop.
class BulkUpdater
def bulk_update(models)
errors = {}
models.each do |model_id, model_attrs|
model = self.class.find(model_id)
unless model.update_attributes(model_attrs)
errors[model_id] = model.errors
end
end
errors
end
end
ActiveRecord::Base.include BulkUpdater
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment