Design Element
Comment on "Attribute Values in Rails"
by Scott Stevenson — Nov 07
First off, in Active Record models the attributes array is used to hold the values as fetched from the database. The instance variables, or attributes, are manipulated by the programmer and persisted back into the model via save or save!

Sure -- this is the same as Core Data, DataCrux, WebObjects, etc.

You can inspect the validity of a model by calling model.valid? or doing:


Iteration on the model.attributes array is failing to persist because attributes returns a hash of the attributes with _clones_ of the attribute value.

Ah. This is a little bit misleading because attributes = {:key = "value"} will actually change the value.

You might want to start coding with open in a tab

I do, but it's really only a reference. It's a lot more helpful if you already know what you're supposed to do.

these subtleties are often covered in the RDoc quite nicely.

Perhaps, but only if you can find the pertinent sections -- there's too much material to just read from start to finish.

You could also achieve the same effect by coding...

Why not just use write_attribute instead?
Back to "Attribute Values in Rails"
Design Element

Copyright © Scott Stevenson 2004-2015