What a hash is?
Hash : Series of key value pairs.
b = { id: 3,
status: "I just ate some delicious brains",
zombie: "Jim" }
Hash Recipe : variable = { key: value }
Ruby Symbol
Hash Read the value
read recipe: variable[:key] => value
Accessing tables
singular and uppercase => lowercase and pluralized table
method find(id)
Alternate Syntax
HASH syntax or DOT syntax
Deep in CRUD
C-Create, R-Read, U-Update, D-Delete
Create
Recipe:
t = TableName.new
t.key = value
t.save
t = TableName.new(hash)
t.save
TableName.create(hash)
Read
find() method and first, last, all
count, order(symbol), limit, where(hash)
Method Chaining
Update
Recipe:
t = TableName.find(id)
t.key = value
t.save
t = TableName.find(id)
t.attributes = hash
t.save
t = TableName.find(id)
t.update(hash)
Delete
Recipe:
t = TableName.find(id)
t.destroy
TableName.find(id).destroy
TableName.destroy_all