Skip to content

Instantly share code, notes, and snippets.

@mickey
Created April 4, 2012 23:26
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 mickey/2306540 to your computer and use it in GitHub Desktop.
Save mickey/2306540 to your computer and use it in GitHub Desktop.
def batch_add(users, activity_type, target)
return false if users.blank? or activity_type.blank? or target.blank?
inserts = []
users.each {|user| inserts.push "('#{user.id}', '#{activity_type}', '#{target.id}', '#{target.class}', UTC_TIMESTAMP())" }
sql = "INSERT INTO activities (`user_id`, `activity_type`, `target_id`, `target_type`, `created_at`) VALUES #{inserts.join(", ")}"
ActiveRecord::Base.connection.execute sql
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment