SlideShare une entreprise Scribd logo
1  sur  53
Télécharger pour lire hors ligne
Beginner To Builder
                        Week 1
                        Richard Schneeman
                        @schneems




June, 2011
Friday, June 10, 2011
Background

                        • Georgia Tech
                        • 5 Years of Rails
                        • Rails dev for Gowalla


@Schneems
Friday, June 10, 2011
About the Class
                        • Why?
                        • Structure
                          • Class & Course Work
                          • Ruby through Rails
                        • 8 Weeks
                          • 1 hour

@Schneems
Friday, June 10, 2011
Rails - Week 1
                        • Ruby
                          • Versus Rails
                          • Data Types
                        • Rails Architecture
                          • MVC (Model View Controller)
                          • ORM (Object Relational Mapping)
                          • RESTful (REpresentational STate)
@Schneems
Friday, June 10, 2011
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

@Schneems
Friday, June 10, 2011
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




@Schneems
Friday, June 10, 2011
Rails is a Web Framework
               •        Develop, deploy, and maintain dynamic web apps
               •        Written using Ruby
               •        Extremely flexible, expressive, and quick
                        development time




@Schneems
Friday, June 10, 2011
Technologies
                        • Html - creates a view
                        • Javascript - makes it interactive
                        • css - makes it pretty
                        • Ruby - Makes it a web app



@Schneems
Friday, June 10, 2011
@Schneems
Friday, June 10, 2011
Ruby Resources
            • why’s (poignant) guide to ruby
              • Free, quirky

               • Programming Ruby (Pickaxe)
                 • Not free, encyclopedic

@Schneems
Friday, June 10, 2011
Ruby Resources
             • Metaprogramming Ruby
               • Skips basics
               • Unleash the power of Ruby




@Schneems
Friday, June 10, 2011
Interactive Ruby Console
                   (IRB) or http://TryRuby.org/




@Schneems
Friday, June 10, 2011
Ruby Strings
                   • Characters (letters, digits, punctuation)
                        surrounded by quotes

                         food = "chunky bacon"
                         puts "I'm hungry for, #{food}!"
                         >> "I'm hungry for, chunky bacon!"


                         "I'm hungry for, chunky bacon!".class
                         >> String



@Schneems
Friday, June 10, 2011
Ruby (numbers)

                        123.class
                        >> Fixnum




                        (123.0).class
                        >> Float




@Schneems
Friday, June 10, 2011
Ruby Symbols
                   •Symbols are lightweight strings
                    • start with a colon
                    • immutable
                        :a, :b or :why_the_lucky_stiff

                        :why_the_lucky_stiff.class
                        >> Symbol




@Schneems
Friday, June 10, 2011
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


@Schneems
Friday, June 10, 2011
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



@Schneems
Friday, June 10, 2011
Ruby Array
                   •Zero Indexed
                        array = [ 1, 2, 3, 4 ]
                        array[0]
                        >> 1

                        array = [ 1, 2, 3, 4 ]
                        array[1]
                        >> 2



@Schneems
Friday, June 10, 2011
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"
@Schneems
Friday, June 10, 2011
Ruby Blocks
                   •Can take arguments
                    • variables surrounded by pipe (|)
                        2.times do |i|
                          puts "hello #{i}"
                        end
                        >> "hello 0"
                        >> "hello 1"




@Schneems
Friday, June 10, 2011
Rails why or why-not?
                        • Speed
                          • developer vs computer
                        • Opinionated framework
                        • Quick moving ecosystem



@Schneems
Friday, June 10, 2011
Rails Architecture
                        • Terminology
                          • DRY
                          • Convention over Configuration
                        • Rails Architecture
                          • MVC (Model View Controller)
                          • ORM (Object Relational Mapping)
                          • RESTful (REpresentational State
                            Transfer)
@Schneems
Friday, June 10, 2011
DRY
                           Don’t Repeat Yourself




                         Reuse, don’t re-invent the...



@Schneems
Friday, June 10, 2011
Convention over
                 Configuration



                       Decrease the number of decisions needed,
                   gaining simplicity but without losing flexibility.

@Schneems
Friday, June 10, 2011
Model-View-Controller
        • Isolates “Domain Logic”
          • Can I See it?
            • View
          • Is it Business Logic?
            • Controller
          • Is it a Reusable Class Logic?
            • Model
@Schneems
Friday, June 10, 2011
Model-View-Controller
        • Generated By Rails
          • Grouped by Folders
          • Connected “AutoMagically”
            • Models
            • Views
            • Controllers
          • Multiple Views Per Controller
@Schneems
Friday, June 10, 2011
Database Backed Models
        • Store and access massive amounts of
          data
        • Table
          • columns (name, type, modifier)
          • rows
                        Table: Users




@Schneems
Friday, June 10, 2011
SQL
                        • Structured Query Language
                         • A way to talk to databases
                         SELECT *
                             FROM Book
                             WHERE price > 100.00
                             ORDER BY title;




@Schneems
Friday, June 10, 2011
SQL operations
                        • insert
                        • query
                        • update and delete
                        • schema creation and modification



@Schneems
Friday, June 10, 2011
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



@Schneems
Friday, June 10, 2011
Object Relational Mapping
         • >> userVariable = User .where(:name => "Bob")
                               models/user.rb
                        class User < ActiveRecord::Base
                        end


          the User class inherits from ActiveRecord::Base




@Schneems
Friday, June 10, 2011
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)




@Schneems
Friday, June 10, 2011
RESTful
                              REpresentational State Transfer
                    •   The state of the message matters
                        •   Different state = different message




                        “You Again?”               “You Again?”
@Schneems
Friday, June 10, 2011
RESTful
                                  REpresentational State Transfer
               •        Servers don’t care about smiles
               •        They do care about how you access them
               •        (HTTP Methods)
                        •   GET
                        •   PUT
                        •   POST
                        •   DELETE



@Schneems
Friday, June 10, 2011
RESTful
                               REpresentational State Transfer
               •        Rails Maps Actions to HTTP Methods
                        •   GET - index, show, new
                        •   PUT - update
                        •   POST - create
                        •   DELETE - destroy




@Schneems
Friday, June 10, 2011
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


@Schneems
Friday, June 10, 2011
Version Control
                        • my_last_update_1.rb
                        • my_realy_last_update_2.rb
                        • really_the_good_code_last_final_new.rb




@Schneems
Friday, June 10, 2011
Version Control
                        • my_last_update_1.rb
                        • my_realy_last_update_2.rb
                        • really_the_good_code_last_final_new.rb




@Schneems
Friday, June 10, 2011
Version Control
                        • my_last_update_1.rb
                        • my_realy_last_update_2.rb
                        • really_the_good_code_last_final_new.rb




@Schneems
Friday, June 10, 2011
Version Control
                        • Make note of whats different
                        • See changes over time
                        • revert back to known state
                        • work with a team



@Schneems
Friday, June 10, 2011
Version Control
                        • Git (recommended)
                        • SVN
                        • Mecurial
                        • Perforce
                        • Many More


@Schneems
Friday, June 10, 2011
Github




                        http://github.com

@Schneems
Friday, June 10, 2011
RubyGems	
                        • Gems
                         • External code “packages”
                        • Rubygems Manages these “packages”
                         gem install keytar
                         irb
                         >> require “rubygems”
                         => true
                         >> require “keytar”
                         => true
@Schneems
Friday, June 10, 2011
@Schneems
Friday, June 10, 2011
Bundler
                        • Install
                          gem install bundler

                        • Gemfiles
                         • specify dependencies
                          source :rubygems

                          gem 'rails', '3.0.4'
                          gem 'unicorn', '3.5.0'
                          gem 'keytar'


@Schneems
Friday, June 10, 2011
Bundler
                        • Install
                          bundle install

                        • installs all gems listed in gemfile
                        • very useful managing across systems



@Schneems
Friday, June 10, 2011
RVM
                        • Ruby Version Manager
                        • Clean Sandbox for each project
                        rvm use ruby-1.8.7-p302


                        rvm use ruby-1.9.2-p180




@Schneems
Friday, June 10, 2011
RVM
                        • Use fresh gemset for each project
                        rvm gemset use gowalla


                        • Switch projects...switch gemsets
                        rvm gemset use keytar




@Schneems
Friday, June 10, 2011
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




@Schneems
Friday, June 10, 2011
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)



@Schneems
Friday, June 10, 2011
IDE
                        • Mac: Textmate
                        • Windows: Notepad ++
                        • Eclipse & Aptana RadRails




@Schneems
Friday, June 10, 2011
Recap
               •        Rails
                        •   Framework
                        •   Convention over Configuration
               •        Ruby
                        •   Expressive Scripting language




@Schneems
Friday, June 10, 2011
Questions?



@Schneems
Friday, June 10, 2011

Contenu connexe

En vedette

En vedette (6)

AJAX?? Não!! Asynchronous Javascript and... JSON!!
AJAX?? Não!! Asynchronous Javascript and... JSON!!AJAX?? Não!! Asynchronous Javascript and... JSON!!
AJAX?? Não!! Asynchronous Javascript and... JSON!!
 
Rails 3 Beginner to Builder 2011 Week 3
Rails 3 Beginner to Builder 2011 Week 3Rails 3 Beginner to Builder 2011 Week 3
Rails 3 Beginner to Builder 2011 Week 3
 
Rails 3 Beginner to Builder 2011 Week 2
Rails 3 Beginner to Builder 2011 Week 2Rails 3 Beginner to Builder 2011 Week 2
Rails 3 Beginner to Builder 2011 Week 2
 
Minicurso JSON & Ajax
Minicurso JSON & AjaxMinicurso JSON & Ajax
Minicurso JSON & Ajax
 
Ruby on Rails for beginners
Ruby on Rails for beginnersRuby on Rails for beginners
Ruby on Rails for beginners
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
 

Similaire à Rails 3 Beginner to Builder 2011 Week 1

2011 JavaOne Apache TomEE Java EE 6 Web Profile
2011 JavaOne Apache TomEE Java EE 6 Web Profile2011 JavaOne Apache TomEE Java EE 6 Web Profile
2011 JavaOne Apache TomEE Java EE 6 Web Profile
David Blevins
 
Clouds against the Floods (RubyConfBR2011)
Clouds against the Floods (RubyConfBR2011) Clouds against the Floods (RubyConfBR2011)
Clouds against the Floods (RubyConfBR2011)
Leonardo Borges
 
Twitter streamingapi rubymongodbv2
Twitter streamingapi rubymongodbv2Twitter streamingapi rubymongodbv2
Twitter streamingapi rubymongodbv2
Jeff Linwood
 
JavaOne 2011 - Going Mobile With Java Based Technologies Today
JavaOne 2011 - Going Mobile With Java Based Technologies TodayJavaOne 2011 - Going Mobile With Java Based Technologies Today
JavaOne 2011 - Going Mobile With Java Based Technologies Today
Wesley Hales
 
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
DATAVERSITY
 
UCLUG TorqueBox - 03/08/2011
UCLUG TorqueBox - 03/08/2011UCLUG TorqueBox - 03/08/2011
UCLUG TorqueBox - 03/08/2011
tobiascrawley
 
Odnoklassniki.ru Architecture
Odnoklassniki.ru ArchitectureOdnoklassniki.ru Architecture
Odnoklassniki.ru Architecture
Dmitry Buzdin
 

Similaire à Rails 3 Beginner to Builder 2011 Week 1 (20)

2011 JavaOne Apache TomEE Java EE 6 Web Profile
2011 JavaOne Apache TomEE Java EE 6 Web Profile2011 JavaOne Apache TomEE Java EE 6 Web Profile
2011 JavaOne Apache TomEE Java EE 6 Web Profile
 
AppScale Talk at SBonRails
AppScale Talk at SBonRailsAppScale Talk at SBonRails
AppScale Talk at SBonRails
 
Are Your Tests Really Helping You?
Are Your Tests Really Helping You?Are Your Tests Really Helping You?
Are Your Tests Really Helping You?
 
Selenium
SeleniumSelenium
Selenium
 
RVM and Ruby Interpreters @ RSC Roma 03/2011
RVM and Ruby Interpreters @ RSC Roma 03/2011RVM and Ruby Interpreters @ RSC Roma 03/2011
RVM and Ruby Interpreters @ RSC Roma 03/2011
 
Clouds against the Floods (RubyConfBR2011)
Clouds against the Floods (RubyConfBR2011) Clouds against the Floods (RubyConfBR2011)
Clouds against the Floods (RubyConfBR2011)
 
Twitter streamingapi rubymongodbv2
Twitter streamingapi rubymongodbv2Twitter streamingapi rubymongodbv2
Twitter streamingapi rubymongodbv2
 
Consuming the Twitter Streaming API with Ruby and MongoDB
Consuming the Twitter Streaming API with Ruby and MongoDBConsuming the Twitter Streaming API with Ruby and MongoDB
Consuming the Twitter Streaming API with Ruby and MongoDB
 
JavaOne 2011 - Going Mobile With Java Based Technologies Today
JavaOne 2011 - Going Mobile With Java Based Technologies TodayJavaOne 2011 - Going Mobile With Java Based Technologies Today
JavaOne 2011 - Going Mobile With Java Based Technologies Today
 
Iwmn architecture
Iwmn architectureIwmn architecture
Iwmn architecture
 
Developing Cocoa Applications with macRuby
Developing Cocoa Applications with macRubyDeveloping Cocoa Applications with macRuby
Developing Cocoa Applications with macRuby
 
Rails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_manyRails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_many
 
Why ruby and rails
Why ruby and railsWhy ruby and rails
Why ruby and rails
 
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
 
Agile xml
Agile xmlAgile xml
Agile xml
 
MongoDB at Sailthru: Scaling and Schema Design
MongoDB at Sailthru: Scaling and Schema DesignMongoDB at Sailthru: Scaling and Schema Design
MongoDB at Sailthru: Scaling and Schema Design
 
UCLUG TorqueBox - 03/08/2011
UCLUG TorqueBox - 03/08/2011UCLUG TorqueBox - 03/08/2011
UCLUG TorqueBox - 03/08/2011
 
Java to scala
Java to scalaJava to scala
Java to scala
 
Odnoklassniki.ru Architecture
Odnoklassniki.ru ArchitectureOdnoklassniki.ru Architecture
Odnoklassniki.ru Architecture
 
What Drove Wordnik Non-Relational?
What Drove Wordnik Non-Relational?What Drove Wordnik Non-Relational?
What Drove Wordnik Non-Relational?
 

Plus de Richard Schneeman

Plus de Richard Schneeman (6)

Scaling the Web: Databases & NoSQL
Scaling the Web: Databases & NoSQLScaling the Web: Databases & NoSQL
Scaling the Web: Databases & NoSQL
 
Rails 3 Beginner to Builder 2011 Week 8
Rails 3 Beginner to Builder 2011 Week 8Rails 3 Beginner to Builder 2011 Week 8
Rails 3 Beginner to Builder 2011 Week 8
 
Potential Friend Finder
Potential Friend FinderPotential Friend Finder
Potential Friend Finder
 
UT on Rails3 2010- Week 4
UT on Rails3 2010- Week 4 UT on Rails3 2010- Week 4
UT on Rails3 2010- Week 4
 
UT on Rails3 2010- Week 2
UT on Rails3 2010- Week 2UT on Rails3 2010- Week 2
UT on Rails3 2010- Week 2
 
UT on Rails3 2010- Week 1
UT on Rails3 2010- Week 1UT on Rails3 2010- Week 1
UT on Rails3 2010- Week 1
 

Dernier

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Dernier (20)

Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 

Rails 3 Beginner to Builder 2011 Week 1

  • 1. Beginner To Builder Week 1 Richard Schneeman @schneems June, 2011 Friday, June 10, 2011
  • 2. Background • Georgia Tech • 5 Years of Rails • Rails dev for Gowalla @Schneems Friday, June 10, 2011
  • 3. About the Class • Why? • Structure • Class & Course Work • Ruby through Rails • 8 Weeks • 1 hour @Schneems Friday, June 10, 2011
  • 4. Rails - Week 1 • Ruby • Versus Rails • Data Types • Rails Architecture • MVC (Model View Controller) • ORM (Object Relational Mapping) • RESTful (REpresentational STate) @Schneems Friday, June 10, 2011
  • 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 @Schneems Friday, June 10, 2011
  • 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 @Schneems Friday, June 10, 2011
  • 7. Rails is a Web Framework • Develop, deploy, and maintain dynamic web apps • Written using Ruby • Extremely flexible, expressive, and quick development time @Schneems Friday, June 10, 2011
  • 8. Technologies • Html - creates a view • Javascript - makes it interactive • css - makes it pretty • Ruby - Makes it a web app @Schneems Friday, June 10, 2011
  • 10. Ruby Resources • why’s (poignant) guide to ruby • Free, quirky • Programming Ruby (Pickaxe) • Not free, encyclopedic @Schneems Friday, June 10, 2011
  • 11. Ruby Resources • Metaprogramming Ruby • Skips basics • Unleash the power of Ruby @Schneems Friday, June 10, 2011
  • 12. Interactive Ruby Console (IRB) or http://TryRuby.org/ @Schneems Friday, June 10, 2011
  • 13. Ruby Strings • Characters (letters, digits, punctuation) surrounded by quotes food = "chunky bacon" puts "I'm hungry for, #{food}!" >> "I'm hungry for, chunky bacon!" "I'm hungry for, chunky bacon!".class >> String @Schneems Friday, June 10, 2011
  • 14. Ruby (numbers) 123.class >> Fixnum (123.0).class >> Float @Schneems Friday, June 10, 2011
  • 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 @Schneems Friday, June 10, 2011
  • 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 @Schneems Friday, June 10, 2011
  • 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 @Schneems Friday, June 10, 2011
  • 18. Ruby Array •Zero Indexed array = [ 1, 2, 3, 4 ] array[0] >> 1 array = [ 1, 2, 3, 4 ] array[1] >> 2 @Schneems Friday, June 10, 2011
  • 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" @Schneems Friday, June 10, 2011
  • 20. Ruby Blocks •Can take arguments • variables surrounded by pipe (|) 2.times do |i| puts "hello #{i}" end >> "hello 0" >> "hello 1" @Schneems Friday, June 10, 2011
  • 21. Rails why or why-not? • Speed • developer vs computer • Opinionated framework • Quick moving ecosystem @Schneems Friday, June 10, 2011
  • 22. Rails Architecture • Terminology • DRY • Convention over Configuration • Rails Architecture • MVC (Model View Controller) • ORM (Object Relational Mapping) • RESTful (REpresentational State Transfer) @Schneems Friday, June 10, 2011
  • 23. DRY Don’t Repeat Yourself Reuse, don’t re-invent the... @Schneems Friday, June 10, 2011
  • 24. Convention over Configuration Decrease the number of decisions needed, gaining simplicity but without losing flexibility. @Schneems Friday, June 10, 2011
  • 25. Model-View-Controller • Isolates “Domain Logic” • Can I See it? • View • Is it Business Logic? • Controller • Is it a Reusable Class Logic? • Model @Schneems Friday, June 10, 2011
  • 26. Model-View-Controller • Generated By Rails • Grouped by Folders • Connected “AutoMagically” • Models • Views • Controllers • Multiple Views Per Controller @Schneems Friday, June 10, 2011
  • 27. Database Backed Models • Store and access massive amounts of data • Table • columns (name, type, modifier) • rows Table: Users @Schneems Friday, June 10, 2011
  • 28. SQL • Structured Query Language • A way to talk to databases SELECT * FROM Book WHERE price > 100.00 ORDER BY title; @Schneems Friday, June 10, 2011
  • 29. SQL operations • insert • query • update and delete • schema creation and modification @Schneems Friday, June 10, 2011
  • 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 @Schneems Friday, June 10, 2011
  • 31. Object Relational Mapping • >> userVariable = User .where(:name => "Bob") models/user.rb class User < ActiveRecord::Base end the User class inherits from ActiveRecord::Base @Schneems Friday, June 10, 2011
  • 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) @Schneems Friday, June 10, 2011
  • 33. RESTful REpresentational State Transfer • The state of the message matters • Different state = different message “You Again?” “You Again?” @Schneems Friday, June 10, 2011
  • 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 @Schneems Friday, June 10, 2011
  • 35. RESTful REpresentational State Transfer • Rails Maps Actions to HTTP Methods • GET - index, show, new • PUT - update • POST - create • DELETE - destroy @Schneems Friday, June 10, 2011
  • 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 @Schneems Friday, June 10, 2011
  • 37. Version Control • my_last_update_1.rb • my_realy_last_update_2.rb • really_the_good_code_last_final_new.rb @Schneems Friday, June 10, 2011
  • 38. Version Control • my_last_update_1.rb • my_realy_last_update_2.rb • really_the_good_code_last_final_new.rb @Schneems Friday, June 10, 2011
  • 39. Version Control • my_last_update_1.rb • my_realy_last_update_2.rb • really_the_good_code_last_final_new.rb @Schneems Friday, June 10, 2011
  • 40. Version Control • Make note of whats different • See changes over time • revert back to known state • work with a team @Schneems Friday, June 10, 2011
  • 41. Version Control • Git (recommended) • SVN • Mecurial • Perforce • Many More @Schneems Friday, June 10, 2011
  • 42. Github http://github.com @Schneems Friday, June 10, 2011
  • 43. RubyGems • Gems • External code “packages” • Rubygems Manages these “packages” gem install keytar irb >> require “rubygems” => true >> require “keytar” => true @Schneems Friday, June 10, 2011
  • 45. Bundler • Install gem install bundler • Gemfiles • specify dependencies source :rubygems gem 'rails', '3.0.4' gem 'unicorn', '3.5.0' gem 'keytar' @Schneems Friday, June 10, 2011
  • 46. Bundler • Install bundle install • installs all gems listed in gemfile • very useful managing across systems @Schneems Friday, June 10, 2011
  • 47. RVM • Ruby Version Manager • Clean Sandbox for each project rvm use ruby-1.8.7-p302 rvm use ruby-1.9.2-p180 @Schneems Friday, June 10, 2011
  • 48. RVM • Use fresh gemset for each project rvm gemset use gowalla • Switch projects...switch gemsets rvm gemset use keytar @Schneems Friday, June 10, 2011
  • 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 @Schneems Friday, June 10, 2011
  • 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) @Schneems Friday, June 10, 2011
  • 51. IDE • Mac: Textmate • Windows: Notepad ++ • Eclipse & Aptana RadRails @Schneems Friday, June 10, 2011
  • 52. Recap • Rails • Framework • Convention over Configuration • Ruby • Expressive Scripting language @Schneems Friday, June 10, 2011

Notes de l'éditeur

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n