Tap into ActiveRecord’s sanitization methods.
by Rabbit
Object instantiation is expensive.
object.association.create(...)
But at the same time you get the power of ActiveRecord’s beautiful sanitization methods. Now you can have that same power without as much overhead.
values = ActiveRecord::Base.send(:sanitize_sql_array, [ '?, ?, ?', x, y, z ])
Familiar syntax is familiar. Now use it.
ActiveRecord::Base.connection.execute(%{INSERT INTO objects (x, y, z) VALUES (#{ values })})
Presto beautiful!




