How to execute arbitrary parameterized SQL in rails How to execute arbitrary parameterized SQL in rails ruby-on-rails ruby-on-rails

How to execute arbitrary parameterized SQL in rails


You could also do this:

updates = ActiveRecord::Base.send(:sanitize_sql_array, ["name = ? and category = ?", name, category])ActiveRecord::Base.connection.execute("update table set #{updates} where id = #{id.to_s.to_i}")

to_s is being called on id before to_i in case it's nil.