Rails 101
Rails is an MVC framework for Ruby focused on building web applications
David Heinemeier Hansson (DHH)
First open sourced July 2004
Extracted from Basecamp
Version 1.0 December 13, 2005
 
August 2006 Apple announces that Rails will be installed by default in OSX Apple announces that Rails will be installed by...
Version 2.0 December 7, 2007 Version 3.0 August 29, 2010 August 29, 2010 August 29, 2010 August 29, 2010 August 29, 2010
Current Version 3.0.10 3.0.10
Convention over Configuration Configuration Configuration
Model Post
Model DB Table Post posts
Model DB Table Controller Post posts PostsController
Model DB Table Controller Index Post posts PostsController /posts posts_path
Model DB Table Controller Index Show Post posts PostsController /posts posts_path /posts/1 post_path(@post)
Model DB Table Controller Index Show Edit Post posts PostsController /posts posts_path /posts/1 post_path(@post) /posts/1/...
Posts table
Primary Key Generated and managed by Rails id Posts table
Primary Key Generated and managed by Rails Foreign Key belongs_to id user_id Posts table
Primary Key Generated and managed by Rails Foreign Key belongs_to Auto-populated timestamps id user_id created_at updated_...
The client-side is important
The client-side is important Prototype Scriptaculous
The client-side is important Prototype Scriptaculous jQuery jQuery jQuery jQuery jQuery jQuery
Generators
Create a new app
Structure
 
Majority of code
Majority of code App/environment config
Majority of code App/environment config Database config (and database!)
Majority of code App/environment config Database config (and database!) App documentation
Majority of code App/environment config Database config (and database!) App documentation Custom code
Majority of code App/environment config Database config (and database!) App documentation Custom code Images, javascript, ...
Majority of code App/environment config Database config (and database!) App documentation Custom code Images, javascript, ...
Majority of code App/environment config Database config (and database!) App documentation Custom code Images, javascript, ...
Majority of code App/environment config Database config (and database!) App documentation Custom code Images, javascript, ...
WEBrick
Scaffolding
Scaffolding Creates CRUD screens for working with a single database table Creates CRUD screens for working with a single d...
Models
ActiveRecord Object Relational Mapping Object Relational Mapping Object Relational Mapping
Database
Migrations
Relationships
Rails console
Validations
Controllers
Actions
Routes
params
session
@
format
“ The essence of XML is this: the problem it solves is not hard, and it does not solve the problem well.”  — Phil Wadler —...
Views
Layouts
Partials
Form helpers
Helpers
html_safe
RESTful
Free web services
ws-*
“ Don’t blame me, I’m just a contractor.”
Let HTTP do what it was meant to do
GET POST PUT DELETE DELETE DELETE DELETE
resources
GET index /posts
GET GET index show /posts /posts/1
GET GET GET index show new /posts /posts/1 /posts/new
GET GET GET POST index show new create /posts /posts/1 /posts/new /posts
GET GET GET POST GET index show new create edit /posts /posts/1 /posts/new /posts /posts/1/edit
GET GET GET POST GET PUT index show new create edit update /posts /posts/1 /posts/new /posts /posts/1/edit /posts/1
GET GET GET POST GET PUT DELETE index show new create edit update destroy /posts /posts/1 /posts/new /posts /posts/1/edit ...
Caching
Fragment caching
Action caching
Page caching
“ There are only two hard problems in Computer Science: cache invalidation and naming things.” — Phil Karlton —  Phil Karl...
Testing
Unit
Functional
Integration
Configuration
Environments
Deployment
 
Questions?
Workshop
Web interface to the Active.com Search API
Example
What you need to know
Required Gems
Required Gems # Gemfile gem 'httparty' gem 'heroku'
Required Gems # Gemfile gem 'httparty' gem 'heroku' rob$ bundle install
Required Gems # Gemfile gem 'httparty' gem 'heroku' rob$ bundle install rob$ gem install bundler
Search API Endpoint http://api.amp.active.com/search?       v=json&          k=keywords&          m=meta:channel%3DRunning...
HTTP call HTTParty.get(url)
Parse JSON JSON.parse(text) HTTP call HTTParty.get(url)
Iterate through array my_array.each do |item| puts item end
Deploy to Heroku git init g it add . g i t commit -m ‘First commit’ he r oku create ... git  p ush heroku master
Questions?
# Gemfile gem 'httparty' gem 'heroku' rob$ bundle install rob$ gem install bundler http://api.amp.active.com/search?      ...
“ Ruby on Rails will never be used in production at Active.”
The End
Upcoming SlideShare
Loading in...5
×

Rails 101

7,340

Published on

Rob Cameron, Senor Software Engineer at The Active Network, walks us through the fundamentals of Ruby on Rails.

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
7,340
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Rails 101

  1. 1. Rails 101
  2. 2. Rails is an MVC framework for Ruby focused on building web applications
  3. 3. David Heinemeier Hansson (DHH)
  4. 4. First open sourced July 2004
  5. 5. Extracted from Basecamp
  6. 6. Version 1.0 December 13, 2005
  7. 8. August 2006 Apple announces that Rails will be installed by default in OSX Apple announces that Rails will be installed by default in OSX Apple announces that Rails will be installed by default in OSX
  8. 9. Version 2.0 December 7, 2007 Version 3.0 August 29, 2010 August 29, 2010 August 29, 2010 August 29, 2010 August 29, 2010
  9. 10. Current Version 3.0.10 3.0.10
  10. 11. Convention over Configuration Configuration Configuration
  11. 12. Model Post
  12. 13. Model DB Table Post posts
  13. 14. Model DB Table Controller Post posts PostsController
  14. 15. Model DB Table Controller Index Post posts PostsController /posts posts_path
  15. 16. Model DB Table Controller Index Show Post posts PostsController /posts posts_path /posts/1 post_path(@post)
  16. 17. Model DB Table Controller Index Show Edit Post posts PostsController /posts posts_path /posts/1 post_path(@post) /posts/1/edit edit_posts_path(@post)
  17. 18. Posts table
  18. 19. Primary Key Generated and managed by Rails id Posts table
  19. 20. Primary Key Generated and managed by Rails Foreign Key belongs_to id user_id Posts table
  20. 21. Primary Key Generated and managed by Rails Foreign Key belongs_to Auto-populated timestamps id user_id created_at updated_at Posts table
  21. 22. The client-side is important
  22. 23. The client-side is important Prototype Scriptaculous
  23. 24. The client-side is important Prototype Scriptaculous jQuery jQuery jQuery jQuery jQuery jQuery
  24. 25. Generators
  25. 26. Create a new app
  26. 27. Structure
  27. 29. Majority of code
  28. 30. Majority of code App/environment config
  29. 31. Majority of code App/environment config Database config (and database!)
  30. 32. Majority of code App/environment config Database config (and database!) App documentation
  31. 33. Majority of code App/environment config Database config (and database!) App documentation Custom code
  32. 34. Majority of code App/environment config Database config (and database!) App documentation Custom code Images, javascript, stylesheets
  33. 35. Majority of code App/environment config Database config (and database!) App documentation Custom code Images, javascript, stylesheets Rails scripts
  34. 36. Majority of code App/environment config Database config (and database!) App documentation Custom code Images, javascript, stylesheets Rails scripts Test code
  35. 37. Majority of code App/environment config Database config (and database!) App documentation Custom code Images, javascript, stylesheets Rails scripts Test code Third party code
  36. 38. WEBrick
  37. 39. Scaffolding
  38. 40. Scaffolding Creates CRUD screens for working with a single database table Creates CRUD screens for working with a single database table Creates CRUD screens for working with a single database table Creates CRUD screens for working with a single database table
  39. 41. Models
  40. 42. ActiveRecord Object Relational Mapping Object Relational Mapping Object Relational Mapping
  41. 43. Database
  42. 44. Migrations
  43. 45. Relationships
  44. 46. Rails console
  45. 47. Validations
  46. 48. Controllers
  47. 49. Actions
  48. 50. Routes
  49. 51. params
  50. 52. session
  51. 53. @
  52. 54. format
  53. 55. “ The essence of XML is this: the problem it solves is not hard, and it does not solve the problem well.” — Phil Wadler — Phil Wadler — Phil Wadler
  54. 56. Views
  55. 57. Layouts
  56. 58. Partials
  57. 59. Form helpers
  58. 60. Helpers
  59. 61. html_safe
  60. 62. RESTful
  61. 63. Free web services
  62. 64. ws-*
  63. 65. “ Don’t blame me, I’m just a contractor.”
  64. 66. Let HTTP do what it was meant to do
  65. 67. GET POST PUT DELETE DELETE DELETE DELETE
  66. 68. resources
  67. 69. GET index /posts
  68. 70. GET GET index show /posts /posts/1
  69. 71. GET GET GET index show new /posts /posts/1 /posts/new
  70. 72. GET GET GET POST index show new create /posts /posts/1 /posts/new /posts
  71. 73. GET GET GET POST GET index show new create edit /posts /posts/1 /posts/new /posts /posts/1/edit
  72. 74. GET GET GET POST GET PUT index show new create edit update /posts /posts/1 /posts/new /posts /posts/1/edit /posts/1
  73. 75. GET GET GET POST GET PUT DELETE index show new create edit update destroy /posts /posts/1 /posts/new /posts /posts/1/edit /posts/1 /posts/1
  74. 76. Caching
  75. 77. Fragment caching
  76. 78. Action caching
  77. 79. Page caching
  78. 80. “ There are only two hard problems in Computer Science: cache invalidation and naming things.” — Phil Karlton — Phil Karlton — Phil Karlton
  79. 81. Testing
  80. 82. Unit
  81. 83. Functional
  82. 84. Integration
  83. 85. Configuration
  84. 86. Environments
  85. 87. Deployment
  86. 89. Questions?
  87. 90. Workshop
  88. 91. Web interface to the Active.com Search API
  89. 92. Example
  90. 93. What you need to know
  91. 94. Required Gems
  92. 95. Required Gems # Gemfile gem 'httparty' gem 'heroku'
  93. 96. Required Gems # Gemfile gem 'httparty' gem 'heroku' rob$ bundle install
  94. 97. Required Gems # Gemfile gem 'httparty' gem 'heroku' rob$ bundle install rob$ gem install bundler
  95. 98. Search API Endpoint http://api.amp.active.com/search? v=json& k=keywords& m=meta:channel%3DRunning& api_key=wuhmn9ye94xn3xnteudxsavw
  96. 99. HTTP call HTTParty.get(url)
  97. 100. Parse JSON JSON.parse(text) HTTP call HTTParty.get(url)
  98. 101. Iterate through array my_array.each do |item| puts item end
  99. 102. Deploy to Heroku git init g it add . g i t commit -m ‘First commit’ he r oku create ... git p ush heroku master
  100. 103. Questions?
  101. 104. # Gemfile gem 'httparty' gem 'heroku' rob$ bundle install rob$ gem install bundler http://api.amp.active.com/search? v=json& k=keywords& m=meta:channel%3DRunning& api_key=wuhmn9ye94xn3xnteudxsavw JSON.parse(text) HTTParty.get(url) my_array.each do |item| puts item end git init g it add . g i t commit -m ‘First commit’ he r oku create ... git p ush heroku master
  102. 105. “ Ruby on Rails will never be used in production at Active.”
  103. 106. The End
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×