I created a Rails model, let's say Car
. I added an attribute to it (not to be saved in the DB) called age
.
class Car < ActiveRecord::Base
attr_accessor :age
end
If I try to print out the attributes of my car, age
does not show up. I found out because attr_accessor is only defining an instance variable.
> my_car = Car.first
> my_car.age = 500
> puts my_car
How can I add an attribute to the record itself that is not persisted to the DB?