Prev | Current Page 44 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"

And it??™s
especially important to understand where Active Record fits into the picture of the MVC framework
when you are building Rails applications.
Active Record Is Primarily Used for CRUD
Database Transactions
There are four general tasks you perform when working with databases: creating (C), reading
(R), updating (U), and deleting (D) rows of data. As a group, these actions are often referred to
as CRUD. Almost all modern applications perform CRUD operations, and Active Record was
specifically designed to make CRUD operations easy to write and understand. The following
examples display the four basic CRUD operations as you would see them in most Active Record
programs:
newacc = Account.new(:username => "Kevin")
newacc.save #=> creates the new record in the account table
temp = Account.find(1)
# => selects the record associated with id of 1 from the account table
temp.username = 'Kevin' # => assigns a value to the username attribute of the object
temp.save #=> does the actual update statement applying the changes we just stated.


Pages:
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56