5. Who am I?
My name: James Edward Gray II
My experience: I’ve been using Ruby since before
Rails was released and in the last five years I’ve worked
on over 30 shipping Rails applications
6. Who am I?
My name: James Edward Gray II
My experience: I’ve been using Ruby since before
Rails was released and in the last five years I’ve worked
on over 30 shipping Rails applications
The One True Dessert Food: Angel food cake
9. Who is my partner?
Her name: Dana Gray
What James thinks about her: She’s cute!
10. Who is my partner?
Her name: Dana Gray
What James thinks about her: She’s cute!
Her secret: She’s having a baby
11. Who is my partner?
Her name: Dana Gray
What James thinks about her: She’s cute!
Her secret: She’s having a baby
Ignore what she says about dessert because we
already learned it is: Angel food cake
15. Your turn!
Please tell us:
Your name
What you know of Ruby/Rails and what you hope to
learn in this training
16. Your turn!
Please tell us:
Your name
What you know of Ruby/Rails and what you hope to
learn in this training
A fun fact (doesn’t have to be your favorite dessert)
19. We Will Teach
Web Development
We are going to teach you how to build complete Web
applications using Rails
20. We Will Teach
Web Development
We are going to teach you how to build complete Web
applications using Rails
It’s a lot to cover and we don’t have time to do it all
21. We Will Teach
Web Development
We are going to teach you how to build complete Web
applications using Rails
It’s a lot to cover and we don’t have time to do it all
We will hit the basics
22. We Will Teach
Web Development
We are going to teach you how to build complete Web
applications using Rails
It’s a lot to cover and we don’t have time to do it all
We will hit the basics
We will dig deeper in some areas
23. We Will Teach
Web Development
We are going to teach you how to build complete Web
applications using Rails
It’s a lot to cover and we don’t have time to do it all
We will hit the basics
We will dig deeper in some areas
We’re assuming you have minimal HTML, CSS,
JavaScript, and programming knowledge
25. We Have Hands-on Labs
Theory is great, and we will teach that about half of the
time, but you learn Rails by building Rails applications
26. We Have Hands-on Labs
Theory is great, and we will teach that about half of the
time, but you learn Rails by building Rails applications
This training is roughly half lab exercises
27. We Have Hands-on Labs
Theory is great, and we will teach that about half of the
time, but you learn Rails by building Rails applications
This training is roughly half lab exercises
You will build a working Rails application over the
next three days
28. We Have Hands-on Labs
Theory is great, and we will teach that about half of the
time, but you learn Rails by building Rails applications
This training is roughly half lab exercises
You will build a working Rails application over the
next three days
Make some new friends and work together!
29. We Have Hands-on Labs
Theory is great, and we will teach that about half of the
time, but you learn Rails by building Rails applications
This training is roughly half lab exercises
You will build a working Rails application over the
next three days
Make some new friends and work together!
I promise you will both learn more that way!
33. We are Interactive
Wake up!
We like questions
Everyone benefits if we turn this into more of a
discussion and less of a lecture
34. We are Interactive
Wake up!
We like questions
Everyone benefits if we turn this into more of a
discussion and less of a lecture
Help us
35. We are Interactive
Wake up!
We like questions
Everyone benefits if we turn this into more of a
discussion and less of a lecture
Help us
Please stop us with questions as you have them
38. Software Moved Online
Ruby on Rails is a framework for building web
applications (interactive Web sites)
39. Software Moved Online
Ruby on Rails is a framework for building web
applications (interactive Web sites)
Web development has exploded
40. Software Moved Online
Ruby on Rails is a framework for building web
applications (interactive Web sites)
Web development has exploded
Think about how many boxed software applications
you buy now verses how many Web sites you use
41. Software Moved Online
Ruby on Rails is a framework for building web
applications (interactive Web sites)
Web development has exploded
Think about how many boxed software applications
you buy now verses how many Web sites you use
Social networking is huge (Twitter, Facebook, …)
42. Software Moved Online
Ruby on Rails is a framework for building web
applications (interactive Web sites)
Web development has exploded
Think about how many boxed software applications
you buy now verses how many Web sites you use
Social networking is huge (Twitter, Facebook, …)
Many mobile applications use Rails as a backend
45. Rails is Ruby, right?
Wrong!
Ruby is a programming
language
The Ruby
Programming
Language
46. Rails is Ruby, right?
Wrong!
Ruby is a programming The Ruby on Rails
language Application
Ruby on Rails, or Rails
Framework
for short, is a The Ruby
framework written in Programming
Ruby Language
47. Rails is Ruby, right?
Wrong!
Ruby is a programming The Ruby on Rails
language Application
Ruby on Rails, or Rails
Framework
for short, is a The Ruby
framework written in Programming
Ruby Language
You will use both
51. The Ruby
Programming Language
Created in Japan in 1995 by Yukihiro Matsumoto (“we
call him “matz”)
It’s a few months older than Java, not new
Is high level with many modern features: Objects,
Exception handling, Garbage collection, …
52. The Ruby
Programming Language
Created in Japan in 1995 by Yukihiro Matsumoto (“we
call him “matz”)
It’s a few months older than Java, not new
Is high level with many modern features: Objects,
Exception handling, Garbage collection, …
It’s very dynamic and expressive, literally allowing you
to mold it to your specific needs
54. The Ruby on Rails
Application Framework
Created in 2003 by David Heinemeier Hansson (we call
him “DHH”)
55. The Ruby on Rails
Application Framework
Created in 2003 by David Heinemeier Hansson (we call
him “DHH”)
Rails was extracted from the real world application
Basecamp
56. The Ruby on Rails
Application Framework
Created in 2003 by David Heinemeier Hansson (we call
him “DHH”)
Rails was extracted from the real world application
Basecamp
It adds Web needs to Ruby: requests and responses,
routing, database modeling, …
57. The Ruby on Rails
Application Framework
Created in 2003 by David Heinemeier Hansson (we call
him “DHH”)
Rails was extracted from the real world application
Basecamp
It adds Web needs to Ruby: requests and responses,
routing, database modeling, …
It also modifies Ruby’s core in quite a few places to
better suit the problem domain of Web applications
60. The Rails Way
Rails often has a preferred approach to a task and it
assumes you will be taking that approach
61. The Rails Way
Rails often has a preferred approach to a task and it
assumes you will be taking that approach
You can almost always choose to do things the non-
Rails way
62. The Rails Way
Rails often has a preferred approach to a task and it
assumes you will be taking that approach
You can almost always choose to do things the non-
Rails way
However, this will not be as easy
63. The Rails Way
Rails often has a preferred approach to a task and it
assumes you will be taking that approach
You can almost always choose to do things the non-
Rails way
However, this will not be as easy
The path of least pain is definitely to do things the Rails
way whenever possible
66. Convention Over
Configuration
Rails has considerably less configuration files than
many other Web frameworks
Instead of always asking, Rails will assume you are
following conventions (no configuration needed)
67. Convention Over
Configuration
Rails has considerably less configuration files than
many other Web frameworks
Instead of always asking, Rails will assume you are
following conventions (no configuration needed)
This makes following the conventions easy
68. Convention Over
Configuration
Rails has considerably less configuration files than
many other Web frameworks
Instead of always asking, Rails will assume you are
following conventions (no configuration needed)
This makes following the conventions easy
If you need to break conventions, things will be less
easy
77. Rails Cares How You Code
DRY
Don’t Repeat Yourself
Rails has tools to help you avoid repeating code
78. Rails Cares How You Code
DRY
Don’t Repeat Yourself
Rails has tools to help you avoid repeating code
YAGNI
79. Rails Cares How You Code
DRY
Don’t Repeat Yourself
Rails has tools to help you avoid repeating code
YAGNI
You Ain’t Gonna Need It
80. Rails Cares How You Code
DRY
Don’t Repeat Yourself
Rails has tools to help you avoid repeating code
YAGNI
You Ain’t Gonna Need It
Rails is agile and can help you change as needed
81. Rails Cares How You Code
DRY
Don’t Repeat Yourself
Rails has tools to help you avoid repeating code
YAGNI
You Ain’t Gonna Need It
Rails is agile and can help you change as needed
Rails encourages TDD (Test Driven Development)
82. The Anatomy
of a Rails Project
Let’s take a first look at how Rails prefers to
keep its house
84. Starting a Rails Project
$ rails -d sqlite3 my_project
Ask Rails to create create
create app/controllers
things for you, so it can create app/helpers
create app/models
do it the way it prefers create app/views/layouts
create config/environments
create config/initializers
create config/locales
create db
create doc
create lib
create lib/tasks
create log
create public/images
create public/javascripts
create public/stylesheets
create script/performance
create test/fixtures
create test/functional
create test/integration
…
85. Starting a Rails Project
$ rails -d sqlite3 my_project
Ask Rails to create create
create app/controllers
things for you, so it can create app/helpers
create app/models
do it the way it prefers create app/views/layouts
create config/environments
create config/initializers
create config/locales
To start a project, just create db
create doc
name it create lib
create lib/tasks
create log
create public/images
create public/javascripts
create public/stylesheets
create script/performance
create test/fixtures
create test/functional
create test/integration
…
86. Starting a Rails Project
$ rails -d sqlite3 my_project
Ask Rails to create create
create app/controllers
things for you, so it can create app/helpers
create app/models
do it the way it prefers create app/views/layouts
create config/environments
create config/initializers
create config/locales
To start a project, just create db
create doc
name it create lib
create lib/tasks
create log
Optionally, you can create public/images
create public/javascripts
create public/stylesheets
choose a database create script/performance
create test/fixtures
create test/functional
create test/integration
…
87. Starting a Rails Project
$ rails -d sqlite3 my_project
Ask Rails to create create
create app/controllers
things for you, so it can create app/helpers
create app/models
do it the way it prefers create app/views/layouts
create config/environments
create config/initializers
create config/locales
To start a project, just create db
create doc
name it create lib
create lib/tasks
create log
Optionally, you can create public/images
create public/javascripts
create public/stylesheets
choose a database create script/performance
create test/fixtures
create test/functional
SQLite is simple create test/integration
…
93. The lib/ and
vendor/ Directories
lib/ is for library code
shared by your entire
application
94. The lib/ and
vendor/ Directories
lib/ is for library code
shared by your entire
application
It also holds
maintenance tasks
95. The lib/ and
vendor/ Directories
lib/ is for library code
shared by your entire
application
It also holds
maintenance tasks
vendor/ is for third
party extensions
(“gems”) or plugins
97. The test/ Directory
Rails encourages you
to test your application
on multiple levels
98. The test/ Directory
Rails encourages you
to test your application
on multiple levels
It also provides tools
for loading test data
and doing performance
testing
110. # SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
config/database.yml
Rails configures a different database
for each environment
111. # SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
config/database.yml
Rails configures a different database
for each environment
118. The Rakefile and
script/ Directory
Rails has scripts for:
Creating new models
and controllers
119. The Rakefile and
script/ Directory
Rails has scripts for:
Creating new models
and controllers
Interactively working
with your models
120. The Rakefile and
script/ Directory
Rails has scripts for:
Creating new models
and controllers
Interactively working
with your models
Installing plugins
121. The Rakefile and
script/ Directory
Rails has scripts for:
Creating new models
and controllers
Interactively working
with your models
Installing plugins
Running your code
122. The Rakefile and
script/ Directory
Rails has scripts for:
Creating new models
and controllers
Interactively working
with your models
Installing plugins
Running your code
Maintenance tasks
124. $ cd my_project
$ script/server
=> Booting Mongrel
=> Rails 2.3.5 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
script/server
Launching your Rails application is as simple as
triggering the server script
125. $ cd my_project
$ script/server
=> Booting Mongrel
=> Rails 2.3.5 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
script/server
Launching your Rails application is as simple as
triggering the server script
126. Rails Up and Running
Browse to http://localhost:3000/
to see your application running