Indi
Aiur · Zellux 的博客 blog.yxwang.me

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

讨论

还没有评论,来说第一句吧。

Aiur · Zellux 的博客 的其他文章