Introduction to Ruby on Rails

Introduction to Ruby on Rails

Course Length: 5 days
Delivery Methods: Available as private class only
Course Benefits
  • Learn to install and configure Ruby and Rails
  • Understand the Model-View-Controller framework architecture
  • Learn to program in Ruby
  • Learn to build database-driven applications with Ruby on Rails
  • Learn to work with templates
  • Learn to use Ajax in Ruby on Rails applications
  • Learn to test Ruby on Rails applications
Course Overview

In this Ruby on Rails training course, students will learn to create database-driven websites using Ruby on Rails. They will learn to install Ruby and Rails, to program in Ruby and use Ajax in their Ruby on Rails applications. This course can be customized to your team's learning needs.

Course Outline
  1. Rails, Breadth-First
    1. Welcome to Ruby on Rails
      1. Divide and conquer: the Model/View/Controller (MVC) architecture
      2. The Ruby story
    2. What Rails Does (and Does for You)
    3. Inside MVC in Rails
      1. How Separate Are the MVC Layers?
    4. A Guided Tour of a Small (but Working!) Rails App
    5. The Rails Application Directory Structure
      1. app/
      2. test/
      3. public/
      4. config/
      5. script/
      6. db/
      7. Rails environments
      8. A word about Rake
    6. Connecting to a Rails Application
      1. Try it out!
    7. The Rails Request/Response Cycle
      1. An action, up close
      2. The view
    8. Some Pre-Auction Housekeeping
      1. Creating the directory for the application
      2. Setting up a default route
      3. Adding a default layout
      4. Tweaking the gem set
  2. Ruby Skills and Tools
    1. Running Ruby Programs
    2. IRB (Interactive Ruby)
      1. Try it out!
    3. Objects and Methods
      1. Sending messages to objects
      2. Messages and methods
      3. Catching non-existent methods
      4. Teaching old objects new tricks
      5. The "self" keyword
    4. Classes
      1. Inheritance
      2. Classes as objects
    5. Strings and Numbers
      1. String literals and interpolation
      2. String operations
        1. String#upcase, #downcase, and #capitalize
        2. String#strip, #lstrip, and #rstrip; #chop and #chomp
        3. String#size (or #length)
      3. Numerics
      4. Arithmetic operators
        1. Arithmetic operators methods!
    6. Symbols
    7. Arrays
      1. Arrays as method return values
      2. Array operations
      3. Getting items from an array
        1. Square brackets are (you guessed it!) a method
      4. Setting array items
    8. Hashes
      1. Hash operations
      2. Determining hash key uniqueness
      3. Alternate hash key syntax
    9. Modules
      1. Modules as namespaces
      2. Modules as class mixins
    10. Control Flow and Conditionals
    11. Instance Variables and Attributes
      1. Instance variables in Rails actions
      2. Attributes
        1. Revising an earlier example, with attr_accessor
        2. Setting and reading a car's fuel
        3. Read-only attributes (and the secret of how attributes work!)
      3. Why you (should) care about attributes
      4. Exercise: explicit vs automatic attribute methods
    12. Iterators
      1. A first iterator example
        1. Yield to the block!
        2. Passing values to a code block
    13. Sorting Collections
      1. Sorting with a code block
      2. sort_by
    14. Filtering Collections
      1. find and find_all (synonyms: detect and select)
      2. map (synonym: collect)
    15. Exercises
  3. The "What": Domain Modeling and ActiveRecord
    1. ActiveRecord Overview
    2. Domain Modeling, Ruby, and Rails
      1. The Scratchpad Domain
      2. Exercise: Modeling the Auction Domain
    3. Programming the Domain
      1. Examining a New Model File
      2. Declaring ActiveRecord Associations
      3. Exercise: Specifying the Associations
    4. Creating the Database Tables
      1. Customizing the Boilerplate Migrations
      2. Association Foreign Keys in Migrations
      3. Exercise: Initializing the Database with Migrations
      4. Alternative Migration Syntax
    5. The Rails Application Console
      1. Starting the Console
      2. Entering Console Commands
      3. Creating Objects in the Console
      4. Exercise: Creating a User, Item, and Auction
  4. Routing and Responses
    1. The Rails Request/Response Cycle
    2. URL Recognition and Routing
    3. Named Routes and URL Generation
      1. Named Route Arguments
      2. Matching Routes the "longhand" Way
    4. Resource Routing
      1. Using Named Routes for Resources
      2. Creating Resource Routing for the Auction
      3. Nested Resources
      4. Do You Really Need to Keep Saying id, id ?
      5. Examining All Your Routes
      6. A Word on REST
      7. Using Named Routes in the Application Console
    5. Creating Controllers and Views
      1. Auto-generating View Template Files
      2. Exercise
      3. Answer
      4. How Rails Chooses a Template
    6. Understanding ERB Templates
      1. Using Embedded Ruby (ERb)
      2. Trying ERb Syntax
      3. Exercise: Fleshing Out the Auctions/Index View
      4. Exercise: Adding an Auction/Show Action
      5. A Couple of Tweaks to the Show View
      6. Exercise: Add a Help Page
  5. Forms
    1. Displaying and Processing Forms in Rails
      1. The Basics of Writing a Rails Form
      2. Update Forms and Pre-filled Form Fields
      3. Form Submission and Processing
      4. The Payoff
      5. New/Save, Create, and update_attributes
      6. Strong Parameters
      7. A Few Other form Helper Methods
        1. password_field
        2. text_area
        3. select
        4. check_box
        5. label
        6. Date selection
        7. The *_tag (non-magic) helpers
      8. Redirecting to a Different Action
      9. Exercise: Write an Item-editing Form and an Update Action
        1. The Actions
        2. The Views
      10. A Little More about the Flash Facility
        1. flashnow
      11. Creating a New Auction
      12. Exercise: Write the newhtmlerb (creation form) View for Auctions
      13. The Auctions/Create Action
        1. Footnote: accepts_nested_attributes_for
  6. Exploring ActiveRecord Techniques
    1. Getting into ActiveRecord
    2. Refining AR Associations
      1. An Auction Belongs to a Seller
      2. Migrating user_id to seller_id
      3. Changing belongs_to :user to belongs_to :seller
      4. Changing has_many :auctions to reflect "seller"
      5. Exercise: Bids and Bidders
    3. Many-to-Many Associations with "Through"
      1. The :source parameter
      2. Exercise: has_many :through the other way around
      3. The Result: Many-to-Many Associations
      4. "Old-style": has_and_belongs_to_many
      5. has_and_belongs_to_many vs has_many :through
      6. Conditions and Limits in Associations
      7. Exercise: Write an Association for Most Recent Bids
    4. Miscellaneous Custom Methods in the Models
      1. Exercise: Writing Custom Methods
      2. Submitting a Bid
      3. ActiveRelation Basics
      4. Enhancing the Views Based on Model Logic
      5. Next Stop: Testing
  7. Testing
    1. Ruby's Test Framework
      1. MiniTest Basics
      2. A First Set of Tests
      3. The Alternative Test Syntax
      4. Testing Classes and Objects
      5. Making Changes to Tested Code
      6. Exercise: Fixing a Test Failure
      7. Answer
    2. From Minitest to Rails Testing
      1. Initializing the Test Database
      2. Fixtures and How to Write Them
      3. Where Fixtures Live
      4. Preprocessing of Fixture Files
      5. Associations in Fixture Files
      6. Exercise: Writing User, Item, and Bid Fixtures
      7. Answer
      8. Examining Fixtures in the Application Console
      9. Using Fixtures in Unit Tests
      10. Some First Unit Tests
      11. Running the Tests
      12. Exercise: Testing the Custom Methods
      13. Answer
    3. Functional Tests
      1. The default functional test file
      2. A first functional test: testing title assignment
      3. Running the functional tests
      4. Examining the content of response HTML
      5. Exercise: Write some functional tests
      6. Answer
      7. The Rails testing landscape
  8. Data Validation with ActiveRecord
    1. Validating ActiveRecord Objects
      1. How (and Where) the Validation Methods Are Called
      2. Application-level vs Database-level Data Validation
      3. How an Object's Validity Is Determined
      4. Saving, Updating, and Creating Invalid Objects
    2. The Role of the Controller in Validating Data
      1. Why set @item?
      2. Displaying the Error Messages
    3. Examples of Selected Validation Methods
      1. length/size
      2. format
      3. uniqueness
      4. Exercise: Adding Validations to the Models
      5. Answers
      6. Require that Starting Bids Consist onLy of Integers
      7. Modifying the Items/Update Action
  9. Exploring ActionPack
    1. ActionPack, the composite library
    2. Custom Helper Methods
      1. When to Write Helper Methods
    3. Partial Templates
      1. Refactoring Forms with Partials
      2. Moving the Duplicate Code into the Partial Template
      3. Exercise: Reuse the Form Partial
      4. Answer
      5. Rendering Collections in Partial Templates
    4. The Session Hash
    5. Controller Filters
      1. Writing a Before Filter
      2. Halting Execution in a Before Filter
      3. Code Blocks as Before Filters
      4. The Scope and Ordering of Filters
      5. After and Around Filters
    6. Differential Responses
      1. Using Alternative Templates
      2. XML with Builder
      3. Next Stop: Cumulative Exercise
  10. Cumulative Exercise: Users and Bids
    1. Consolidating Your Gains
    2. Exercise Description 1: High-level
    3. Exercise Description 2: Thick Description
      1. Passwords
      2. User Registration: Name, Email, Password
      3. Logging In and Out
      4. Sessions and the @current_user
      5. Fleshing Out Seller and Owner
      6. Bidding
      7. Securing the Item Editing Process
      8. Showing Links
      9. Tests, Old and New
    4. The Results
      1. The login/logout Routes
      2. User Authentication with the Session Hash
      3. Requiring a User at the Filter Level
      4. Fleshing Out Seller and Owner
      5. Creating a Bid
      6. Securing the Item Editing Process
      7. Selected Tests
  11. Using CSS and JavaScript
    1. The Basic Asset Pipeline Architecture
      1. Concatenation and Minification of Assets
      2. An Example: Toggling Display of the Scratchpad Comment
      3. Exercise: Displaying and Hiding Bid History
    2. Ajax
      1. Example: Ajax in the Scratchpads Application
      2. Exercise: Make Bidding an Ajax Request
      3. The End of the Line!
Class Materials

Each student will receive a comprehensive set of materials, including course notes and all the class examples.

Class Prerequisites

Experience in the following is required for this Ruby on Rails class:

  • HTML

Experience in the following would be useful for this Ruby on Rails class:

  • Server-side programming experience
  • SQL
Request a Private Class
  • Private Class for your Team
  • Online or On-location
  • Customizable
  • Expert Instructors
Request Pricing