Wed Development on Rails
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Wed Development on Rails

  • 1,538 views
Uploaded on

This was the first speech of a three day Rails training I gave in Tulsa, OK in the spring 2010.

This was the first speech of a three day Rails training I gave in Tulsa, OK in the spring 2010.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,538
On Slideshare
1,536
From Embeds
2
Number of Embeds
2

Actions

Shares
Downloads
42
Comments
0
Likes
1

Embeds 2

http://www.slideshare.net 1
https://www.linkedin.com 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

Transcript

  • 1. Web Development on Rails Introducing James and Dana Gray, this training, and Ruby on Rails
  • 2. Teachers and Students We’re going to spend three days working together, so let’s get to know each other
  • 3. Who am I?
  • 4. Who am I? My name: James Edward Gray II
  • 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
  • 7. Who is my partner?
  • 8. Who is my partner? Her name: Dana Gray
  • 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
  • 12. Your turn!
  • 13. Your turn! Please tell us:
  • 14. Your turn! Please tell us: Your name
  • 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)
  • 17. This Training What the heck are we doing here?
  • 18. We Will Teach Web Development
  • 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
  • 24. We Have Hands-on Labs
  • 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!
  • 30. We are Interactive
  • 31. We are Interactive Wake up!
  • 32. We are Interactive Wake up! We like questions
  • 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
  • 36. Ruby on Rails What exactly is this “Rails” thing?
  • 37. Software Moved Online
  • 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
  • 43. Rails is Ruby, right?
  • 44. Rails is Ruby, right? Wrong!
  • 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
  • 48. The Ruby Programming Language
  • 49. The Ruby Programming Language Created in Japan in 1995 by Yukihiro Matsumoto (“we call him “matz”)
  • 50. 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
  • 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
  • 53. The Ruby on Rails Application Framework
  • 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
  • 58. Railsisms Rails is very opinionated software!
  • 59. The Rails Way
  • 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
  • 64. Convention Over Configuration
  • 65. Convention Over Configuration Rails has considerably less configuration files than many other Web frameworks
  • 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
  • 69. MVC Architecture
  • 70. MVC Architecture Rails separates code:
  • 71. MVC Architecture Rails separates code: Database Models (database– Models business logic)
  • 72. MVC Architecture Rails separates code: Database Models (database– Models business logic) Views (Web pages, RSS feeds, …) View Browser
  • 73. MVC Architecture Rails separates code: Database Models (database– Models business logic) Views (Web pages, Controller RSS feeds, …) View Controllers (manage communication) Browser
  • 74. Rails Cares How You Code
  • 75. Rails Cares How You Code DRY
  • 76. Rails Cares How You Code DRY Don’t Repeat Yourself
  • 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
  • 83. Starting a Rails Project
  • 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 …
  • 88. The app/ Directory
  • 89. The app/ Directory The heart of your application
  • 90. The app/ Directory The heart of your application You can see the MVC design in here
  • 91. The app/ Directory The heart of your application You can see the MVC design in here Helpers relate to views
  • 92. The lib/ and vendor/ Directories
  • 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
  • 96. The test/ Directory
  • 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
  • 99. The public/ Directory
  • 100. The public/ Directory For static assets:
  • 101. The public/ Directory For static assets: Static HTML pages
  • 102. The public/ Directory For static assets: Static HTML pages Error Pages
  • 103. The public/ Directory For static assets: Static HTML pages Error Pages Images and CSS
  • 104. The public/ Directory For static assets: Static HTML pages Error Pages Images and CSS JavaScript (Prototype and script.aculo.us included)
  • 105. The config/ Directory
  • 106. The config/ Directory Where you can change Rails configuration
  • 107. The config/ Directory Where you can change Rails configuration It’s all set to conventions for you
  • 108. The config/ Directory Where you can change Rails configuration It’s all set to conventions for you Note that Rails can run in three different modes
  • 109. config/database.yml Rails configures a different database for each environment
  • 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
  • 112. The log/ Directory
  • 113. The log/ Directory Rails logs events from each of its environments
  • 114. The log/ Directory Rails logs events from each of its environments This helps debug issues
  • 115. The log/ Directory Rails logs events from each of its environments This helps debug issues It can also be used for statistics tracking
  • 116. The Rakefile and script/ Directory
  • 117. The Rakefile and script/ Directory Rails has scripts for:
  • 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
  • 123. script/server Launching your Rails application is as simple as triggering the server script
  • 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
  • 127. Questions?
  • 128. Creating a Rails Application Lab Your book has instructions for getting started with a Rails application: team up and try it!