I run my own computer services business called
Tech Girl Wonder.And I’m hiring.
I do ruby programming with Logical Reality Design,
a Rails development shop. Hire us!
• This is my take on the subject, not the one true way.
• For the smarty pants in the room, I’m skipping over a lot.
Possibly even saying things that aren’t always true.
• There will be time for questions.
• This is not a lecture, only the first 15-30 minutes are.
A Few CAVEATS
Why This Talk?
• I think I’ve noticed some patterns in where new people get
stuck learning Rails
• I think it has to do with the parts of Rails that are closer to
traditional computer programming and very different from
• Specifically, I think people get stuck on the ‘M’ in the MVC,
i.e ActiveRecord and its connection to an SQL database.
Static Web Sites
Give me a
Static web page: is delivered
to the user exactly as stored.
ed by App
ServerClient View Controller
WHAT IS THE MODEL?
• A model of data represented by the application
• Rails stores its data in a relational database. (usually)
• You access data in relational databases with SQL queries
• SQL queries are complex and hard to write
• ActiveRecord is there to make that easier and “better”
What is A RELATIONAL
• A series of data tables (like Excel spreadsheets) that are
connected to each other through relationships
• Hint: Spend some time with Filemaker or Access
RelationAL Database Example
Id Weight Stale
1 6oz TRUE
2 8oz FALSE
3 5oz FALSE
Id Name Country
1 Swiss Switzerland
2 American U.S.
3 Harvarty Denmark
Id Name Address
1 Cheesetopia 123 Fake St.
2 I Love Cheese 8675 Threeonine Ave.
3 Bob’s Cheeses 1 Infinite Loop
Id Weight Stale TypeID ShopID
1 6oz TRUE 1 2
2 8oz FALSE 3 3
3 5oz FALSE 2 1
SQL: Standard Query Lanaguage
SELECT * FROM CHEESES
WHERE cheeses.stale =
class CheeseType < ActiveRecord::Base
attr_accessible :name, :country
class Cheese < ActiveRecord::Base
attr_accessible :weight, :stale
class CheeseStore < ActiveRecord::Base
attr_accessible :name, :address
WoRKING WITH ACTIVE
cheese_type.country = “France”
Cheese.where(:weight => 4.0..10.0)
[“SWISS”,“HAVARTI”]}).where(:stale => false)
The KEY PIECE OF GLUE:
Migrationsrails generate model cheeses weight:decimal stale:boolean cheese_type_id:integer
class CreateCheeses < ActiveRecord::Migration
create_table :cheeses do |t|
Oh wait, so that’s what rake db:migrate does!