Created
April 4, 2012 23:26
-
-
Save mickey/2306541 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.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