天天看點

《Rails Recipes》Part II Database Recipes 知識點總結 六

Make Dumb Data Smart with composed_of() 通過composed_of() 使呆闆的資料變聰明

基本文法如下

下面舉個例子

============================================

customer.address_street = "Hyancintvej"

customer.address_city = "Copenhagen"

customer.address # => Address.new("Hyancintvej", "Copenhagen")

customer.address = Address.new("May Street", "Chicago")

customer.address_street # => "May Street"

customer.address_city # => "Chicago"

=============================================

但是對于給@SomeModel.some_attribute.special_class_attr指派是不會儲存的

要建立一個@some_attribute并指派,然後@[email protected]_attribute才行