Manage connections by using ActiveRecord

Insert data using ActiveRecord to manage opening and closing a connection to Cloud SQL for MySQL.

Documentation pages that include this code sample

To view the code sample used in context, see the following documentation:

Code sample


@vote = candidate: candidate

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

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.