Rails bruger forbindelsespooling, så dit bedste bud er at bruge en alias_method_chain til ActiveRecord::ConnectionAdapters::ConnectionPool#new_connection
module ActiveRecord
Module ConnectionAdapters
class ConnectionPool
alias_method_chain :new_connection, :my_stuff
private
def new_connection_with_my_stuff
c = new_connection_without_my_stuff
# Do your stuff with
# c.exec(<your sql command>)
c
end
end
end
end