/ Published in: Ruby

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
def self.insert_multiple_rows(columns, values) values_statement = "" values.each { |row| values_statement << "(#{columns.length.times} connection.execute(<<-EOF) INSERT INTO #{table_name} (#{columns.join(",")}) VALUES #{values_statement} EOF end Now you'll be able to call, for example: columns = ["username","real_name", "password"] values = [ ["divoxx", "Rodrigo", "foo"], ["johng", "John Gary", "yay"] ] User.insert_multiple_rows(columns, values)
Comments
