ActiveRecord 的一些细节

Aiur · Zellux at 
对象属性 ActiveRecord 对象在数据库中的属性并不是以实体变量的方式保存的,如果要为一个属性设置默认值的话,class Item < ActiveRecord::Base def category @category || 'n/a' endend 这样的实现是不可行的。读取和修改这些属性时应该使用 read_attribute 和 write_attribute:class Item < ActiveRecord::Base def category read_attribute(:category) || 'n/a' endendHash 和相等性 Activ……