Prev | Current Page 220 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"


Basically, the acts_as_* methods add various methods to your Active Record objects so
that they act as other types of objects or collections.
?– Note It??™s important to keep in mind that acts_as does not actually change the object type. It merely adds
functionality to the Active Record object.
CHAPTER 5 ?–  BONUS FEATURES 92
By default, Active Record has three primary acts_as methods??”acts_as_list, acts_as_
tree, and acts_as_nested-set??”though others do exist and more are in development. Each
acts_as method is really quite useful and comes with its own set of rules and implementation
options. Because acts_as features work on collections, each relies on the various data association
methods (see Chapter 4) to work properly.
Acting as a List
We??™ve all seen top-ten lists; we??™ve all put together a grocery list, and as programmers, we??™ve
certainly all had to deal with to-do lists. So I??™m pretty sure we??™re all familiar with the core traits
of a list. As I??™m sure we all know, lists can be powerful things. It only makes sense that, at times,
you may want to add list-like functionality to some of your Active Record collections, and as
luck would have it, Active Record gives you just that ability with an acts_as_list method.


Pages:
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232