Prev | Current Page 404 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"

to_xml(:only => [ :last_name ])
# =>
Pytel

account.to_xml(:except => [ :last_name ])
# =>
1
Chad
1
2006-11-10T10:22:56-05:00

CHAPTER 7 ?–  WORKING WITH LEGACY SCHEMA 182
As previously mentioned, associations are not expanded in the XML by default. To cause
certain associations to also be included in the XML, use the :include option:
account.to_xml(:include => [ :site ])
# =>

1
Pytel
Chad

1
Account Site

1
2006-11-10T10:22:56-05:00

Importing XML
While Active Record contains a to_xml method for writing XML, it does not contain a from_xml
method for reading it. Thankfully, Active Support extends the hash object with a create_
from_xml method.


Pages:
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416