Some simple ruby script that make use of ActiveRecord CRUD tasks outside of Rails.
CRUD stands for Create, Read, Update and Delete. These are the typical operations that we perform on data in a database.
Before you continue you should read the official Rails guide on Active Record Basics.
Each one of these following scripts depends on the ar.rb
file to load up the database connection. The following four scripts show how to perform CRUD on data in a customers
table using a Customer
mode.
- Read: active_record_read.rb
- Create: active_record_create.rb
- Update: active_record_update.rb
- Delete: active_record_delete.rb
In a database we can relate data across different tables using foreign key associations. Here's an example of an association where each row in the customers
table "belongs to" a row in the provinces
table by way of a province_id
foreign key:
- Associations: active_record_assoc.rb
- Active Record Query Interface
- Active Record Validations
- Active Record Associations
- Rails Database Migrations
This code was heavily inspired by Luiz Cezer's Active-Record-and-Migrations-without-Rails.
This is free and unencumbered software released into the public domain. See UNLICENSE for details.