Ruby: Koneksi ActiveRecord SQL Server

Mendemonstrasikan penyisipan data menggunakan ActiveRecord untuk mengelola pembukaan dan menutup koneksi ke Cloud SQL untuk SQL Server.

Mempelajari lebih lanjut

Untuk dokumentasi mendetail yang menyertakan contoh kode ini, lihat referensi berikut:

Contoh kode

Ruby

Untuk melakukan autentikasi ke Cloud SQL untuk SQL Server, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

@vote = Vote.new candidate: candidate

# ActiveRecord creates and executes your SQL and automatically
# handles the opening and closing of the database connection.
if @vote.save
  render json: "Vote successfully cast for \"#{@vote.candidate}\" at #{@vote.time_cast} PST!"
else
  render json: @vote.errors, status: :unprocessable_entity
end

Langkah berikutnya

Untuk menelusuri dan memfilter contoh kode untuk produk Google Cloud lainnya, lihat Google Cloud browser contoh.