Simple Reference to ActiveRecord

This document provides a simple reference to ActiveRecord methods, which can be used in a rails controller or in the rails console. The examples are based on the Airport model, which can be created with the following commands:

   rails generate model Airport city:string code:string
   rake db:migrate

The model (class) name is Airport. Note that replacing model with scaffold in the above command will create both the model and the scaffold code for the application.

The methods are categorized into two groups: those that can be called with a model name (class methods) and those that can be called with an object (instance methods). The examples will use airport1 and airport2 as example objects (records) that belong to the Airport class.

Class methods

Object methods