Rails 3 Beginner to Builder 2011 Week 1

14,298 views

Published on

This is the first of 8 presentations given at University of Texas during my Beginner to Builder Rails 3 Class. For more info and the whole series including video presentations at my blog:


http://schneems.tumblr.com/tagged/Rails-3-beginner-to-builder-2011

Published in: Education, Technology
3 Comments
9 Likes
Statistics
Notes
No Downloads
Views
Total views
14,298
On SlideShare
0
From Embeds
0
Number of Embeds
10,067
Actions
Shares
0
Downloads
172
Comments
3
Likes
9
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Rails 3 Beginner to Builder 2011 Week 1

    1. 1. Beginner To Builder Week 1 Richard Schneeman @schneemsJune, 2011Friday, June 10, 2011
    2. 2. Background • Georgia Tech • 5 Years of Rails • Rails dev for Gowalla@SchneemsFriday, June 10, 2011
    3. 3. About the Class • Why? • Structure • Class & Course Work • Ruby through Rails • 8 Weeks • 1 hour@SchneemsFriday, June 10, 2011
    4. 4. Rails - Week 1 • Ruby • Versus Rails • Data Types • Rails Architecture • MVC (Model View Controller) • ORM (Object Relational Mapping) • RESTful (REpresentational STate)@SchneemsFriday, June 10, 2011
    5. 5. Rails - Week 1 •Workspace • Version Control - Keep your code safe • RubyGems - Use other’s code • Bundler - Manage Dependencies • RVM - Keep your system clean • Tests - make sure it works@SchneemsFriday, June 10, 2011
    6. 6. Ruby Versus Rails • Ruby - Is a programming Language • Like C# or Python • Can be used to program just about anything • Rails - Is a Framework • Provides common web functionality • Focus on your app, not on low level details@SchneemsFriday, June 10, 2011
    7. 7. Rails is a Web Framework • Develop, deploy, and maintain dynamic web apps • Written using Ruby • Extremely flexible, expressive, and quick development time@SchneemsFriday, June 10, 2011
    8. 8. Technologies • Html - creates a view • Javascript - makes it interactive • css - makes it pretty • Ruby - Makes it a web app@SchneemsFriday, June 10, 2011
    9. 9. @SchneemsFriday, June 10, 2011
    10. 10. Ruby Resources • why’s (poignant) guide to ruby • Free, quirky • Programming Ruby (Pickaxe) • Not free, encyclopedic@SchneemsFriday, June 10, 2011
    11. 11. Ruby Resources • Metaprogramming Ruby • Skips basics • Unleash the power of Ruby@SchneemsFriday, June 10, 2011
    12. 12. Interactive Ruby Console (IRB) or http://TryRuby.org/@SchneemsFriday, June 10, 2011
    13. 13. Ruby Strings • Characters (letters, digits, punctuation) surrounded by quotes food = "chunky bacon" puts "Im hungry for, #{food}!" >> "Im hungry for, chunky bacon!" "Im hungry for, chunky bacon!".class >> String@SchneemsFriday, June 10, 2011
    14. 14. Ruby (numbers) 123.class >> Fixnum (123.0).class >> Float@SchneemsFriday, June 10, 2011
    15. 15. Ruby Symbols •Symbols are lightweight strings • start with a colon • immutable :a, :b or :why_the_lucky_stiff :why_the_lucky_stiff.class >> Symbol@SchneemsFriday, June 10, 2011
    16. 16. Ruby Hash •A hash is a dictionary surrounded by curly braces. •Dictionaries match words with their definitions. my_var = {:sup => "dog", :foo => "bar"} my_var[:foo] >> "bar" {:sup => "dog", :foo => "bar"}.class >> Hash@SchneemsFriday, June 10, 2011
    17. 17. Ruby Array •An array is a list surrounded by square brackets and separated by commas. array = [ 1, 2, 3, 4 ] array.first >> 1 [ 1, 2, 3, 4 ].class >> Array@SchneemsFriday, June 10, 2011
    18. 18. Ruby Array •Zero Indexed array = [ 1, 2, 3, 4 ] array[0] >> 1 array = [ 1, 2, 3, 4 ] array[1] >> 2@SchneemsFriday, June 10, 2011
    19. 19. Ruby Blocks •Code surrounded by curly braces 2.times { puts "hello"} >> "hello" >> "hello" •Do and end can be used instead 2.times do puts "hello" end >> "hello" >> "hello"@SchneemsFriday, June 10, 2011
    20. 20. Ruby Blocks •Can take arguments • variables surrounded by pipe (|) 2.times do |i| puts "hello #{i}" end >> "hello 0" >> "hello 1"@SchneemsFriday, June 10, 2011
    21. 21. Rails why or why-not? • Speed • developer vs computer • Opinionated framework • Quick moving ecosystem@SchneemsFriday, June 10, 2011
    22. 22. Rails Architecture • Terminology • DRY • Convention over Configuration • Rails Architecture • MVC (Model View Controller) • ORM (Object Relational Mapping) • RESTful (REpresentational State Transfer)@SchneemsFriday, June 10, 2011
    23. 23. DRY Don’t Repeat Yourself Reuse, don’t re-invent the...@SchneemsFriday, June 10, 2011
    24. 24. Convention over Configuration Decrease the number of decisions needed, gaining simplicity but without losing flexibility.@SchneemsFriday, June 10, 2011
    25. 25. Model-View-Controller • Isolates “Domain Logic” • Can I See it? • View • Is it Business Logic? • Controller • Is it a Reusable Class Logic? • Model@SchneemsFriday, June 10, 2011
    26. 26. Model-View-Controller • Generated By Rails • Grouped by Folders • Connected “AutoMagically” • Models • Views • Controllers • Multiple Views Per Controller@SchneemsFriday, June 10, 2011
    27. 27. Database Backed Models • Store and access massive amounts of data • Table • columns (name, type, modifier) • rows Table: Users@SchneemsFriday, June 10, 2011
    28. 28. SQL • Structured Query Language • A way to talk to databases SELECT * FROM Book WHERE price > 100.00 ORDER BY title;@SchneemsFriday, June 10, 2011
    29. 29. SQL operations • insert • query • update and delete • schema creation and modification@SchneemsFriday, June 10, 2011
    30. 30. Object Relational Mapping • Maps database backend to ruby objects • ActiveRecord (Rail’s Default ORM) >> userVariable = User.where(:name => "Bob") Generates: SELECT "users".* FROM "users" WHERE (name = bob) >> userVariable.name => Bob@SchneemsFriday, June 10, 2011
    31. 31. Object Relational Mapping • >> userVariable = User .where(:name => "Bob") models/user.rb class User < ActiveRecord::Base end the User class inherits from ActiveRecord::Base@SchneemsFriday, June 10, 2011
    32. 32. Object Relational Mapping • >> userVariable = User. where(:name => "Bob") where is the method that looks in the database AutoMagically in the User Table (if you made one)@SchneemsFriday, June 10, 2011
    33. 33. RESTful REpresentational State Transfer • The state of the message matters • Different state = different message “You Again?” “You Again?”@SchneemsFriday, June 10, 2011
    34. 34. RESTful REpresentational State Transfer • Servers don’t care about smiles • They do care about how you access them • (HTTP Methods) • GET • PUT • POST • DELETE@SchneemsFriday, June 10, 2011
    35. 35. RESTful REpresentational State Transfer • Rails Maps Actions to HTTP Methods • GET - index, show, new • PUT - update • POST - create • DELETE - destroy@SchneemsFriday, June 10, 2011
    36. 36. Work Environment • Version Control - Keep your code safe • RubyGems - Use other’s code • Bundler - Manage Dependencies • RVM - Keep your system clean • Tests - make sure it works@SchneemsFriday, June 10, 2011
    37. 37. Version Control • my_last_update_1.rb • my_realy_last_update_2.rb • really_the_good_code_last_final_new.rb@SchneemsFriday, June 10, 2011
    38. 38. Version Control • my_last_update_1.rb • my_realy_last_update_2.rb • really_the_good_code_last_final_new.rb@SchneemsFriday, June 10, 2011
    39. 39. Version Control • my_last_update_1.rb • my_realy_last_update_2.rb • really_the_good_code_last_final_new.rb@SchneemsFriday, June 10, 2011
    40. 40. Version Control • Make note of whats different • See changes over time • revert back to known state • work with a team@SchneemsFriday, June 10, 2011
    41. 41. Version Control • Git (recommended) • SVN • Mecurial • Perforce • Many More@SchneemsFriday, June 10, 2011
    42. 42. Github http://github.com@SchneemsFriday, June 10, 2011
    43. 43. RubyGems • Gems • External code “packages” • Rubygems Manages these “packages” gem install keytar irb >> require “rubygems” => true >> require “keytar” => true@SchneemsFriday, June 10, 2011
    44. 44. @SchneemsFriday, June 10, 2011
    45. 45. Bundler • Install gem install bundler • Gemfiles • specify dependencies source :rubygems gem rails, 3.0.4 gem unicorn, 3.5.0 gem keytar@SchneemsFriday, June 10, 2011
    46. 46. Bundler • Install bundle install • installs all gems listed in gemfile • very useful managing across systems@SchneemsFriday, June 10, 2011
    47. 47. RVM • Ruby Version Manager • Clean Sandbox for each project rvm use ruby-1.8.7-p302 rvm use ruby-1.9.2-p180@SchneemsFriday, June 10, 2011
    48. 48. RVM • Use fresh gemset for each project rvm gemset use gowalla • Switch projects...switch gemsets rvm gemset use keytar@SchneemsFriday, June 10, 2011
    49. 49. Testing • Does your code 6 months ago work? • What did it do again? • Manual Versus Programatic • Save Time in the long road by progamatic Testing@SchneemsFriday, June 10, 2011
    50. 50. Testing • Test framework built into Rails • Swap in other frame works • Use Continuous Integration (CI) • All tests green • When your(neverapp breaks, write a test for it web again)@SchneemsFriday, June 10, 2011
    51. 51. IDE • Mac: Textmate • Windows: Notepad ++ • Eclipse & Aptana RadRails@SchneemsFriday, June 10, 2011
    52. 52. Recap • Rails • Framework • Convention over Configuration • Ruby • Expressive Scripting language@SchneemsFriday, June 10, 2011
    53. 53. Questions?@SchneemsFriday, June 10, 2011

    ×