Prev | Current Page 494 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"

find(1).attributes # => { "last_name" => "Pytel", "first_name" => "Chad"}
APPENDIX ?–  ACTIVE RECORD METHODS IN DETAIL 225
The only options are :except and :only, and each should be an array of the attribute
names. :except specifies that all attributes should be included in the return hash except for
those in the specified array. :only specifies that only the attributes whose names match those
in the specified array should be included in the returned hash:
Account.find(1).attributes({:only => ["last_name"]})
# => { "last_name" => "Pytel" }
Account.find(1).attributes({:except => ["last_name"])
# => { "first_name" => "Chad" }
attributes=(new_attributes)
This method accepts a hash with keys matching the attribute names of this object and sets all
of the object??™s attributes at once using this hash. You can protect sensitive attributes from this
form of mass assignment by using the attr_protected and attr_accessible methods:
Account.find(1).attributes = { :last_name => "Pytel", :first_name => "Chad" }
attributes_before_type_cast()
Return a hash of attributes and their cloned values before typecasting and deserialization with
this method.


Pages:
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506