Learning Rails 3

Book description

If you’re a web developer or designer ready to learn Rails, this unique book is the ideal way to start.

Rather than throw you into the middle of the framework’s Model-View-Controller architecture, Learning Rails 3 works from the outside in. You’ll begin with the foundations of the Web you already know, and learn how to create something visible with Rails’ view layer. Then you’ll tackle the more difficult inner layers: the database models and controller code.

All you need to get started is HTML experience. Each chapter includes exercises and review questions to test your understanding as you go.

  • Present content by building an application with a basic view and a simple controller
  • Build forms and process their results, progressing from simple to more complex
  • Connect forms to models by setting up a database, and create code that maps to database structures
  • Use Rails scaffolding to build applications from a view-centric perspective
  • Add common web application elements such as sessions, cookies, and authentication
  • Build applications that combine data from multiple tables
  • Send and receive email messages from your applications

"Learning Rails 3 feels like a brisk pair programming session with professionals who know how to use Ruby on Rails to get things done, and get them done well."
-Alan Harris, author of Sinatra: Up and Running

Publisher resources

View/Submit Errata

Table of contents

  1. Learning Rails 3
  2. A Note Regarding Supplemental Files
  3. Preface
    1. Who This Book Is For
    2. Who This Book Is Not For
    3. What You’ll Learn
    4. Ruby and Rails Style
    5. Other Options
    6. Rails Versions
    7. If You Have Problems Making Examples Work
    8. If You Like (or Don’t Like) This Book
    9. Conventions Used in This Book
    10. Using Code Examples
    11. Safari® Books Online
    12. How to Contact Us
    13. Acknowledgments
  4. 1. Starting Up Ruby on Rails
    1. If You Run Windows, You’re Lucky
    2. Getting Started at the Command Line
    3. Starting Up Rails
    4. Test Your Knowledge
      1. Quiz
      2. Answers
  5. 2. Rails on the Web
    1. Creating Your Own View
    2. What Are All Those Folders?
    3. Adding Some Data
    4. How Hello World Works
    5. Adding Logic to the View
    6. Test Your Knowledge
      1. Quiz
      2. Answers
  6. 3. Adding Web Style
    1. I Want My CSS!
    2. Specifying Stylesheets
    3. Creating a Layout for a Controller
    4. Choosing a Layout from a Controller
    5. Sharing Template Data with the Layout
    6. Setting a Default Page
    7. Test Your Knowledge
      1. Quiz
      2. Answers
  7. 4. Managing Data Flow: Controllers and Models
    1. Getting Started, Greeting Guests
    2. Application Flow
    3. Keeping Track: A Simple Guestbook
      1. Connecting to a Database Through a Model
      2. Connecting the Controller to the Model
        1. Storing data using the model
        2. Retrieving data from the model and showing it
    4. Finding Data with ActiveRecord
    5. Test Your Knowledge
      1. Quiz
      2. Answers
  8. 5. Accelerating Development with Scaffolding and REST
    1. A First Look at Scaffolding
    2. REST and Controller Best Practices
      1. Websites and Web Applications
      2. Toward a Cleaner Approach
    3. Examining a RESTful Controller
      1. Index: An Overview of Data
      2. Show: Just One Row of Data
      3. New: A Blank Set of Data Fields
      4. Edit: Hand Me That Data, Please
      5. Create: Save Something New
      6. Put This Updated Record In
      7. Destroy It
    4. Escaping the REST Prison
    5. Test Your Knowledge
      1. Quiz
      2. Answers
  9. 6. Presenting Models with Forms
    1. More Than a Name on a Form
    2. Generating HTML Forms with Scaffolding
    3. Form as a Wrapper
    4. Creating Text Fields and Text Areas
    5. Labels
    6. Creating Checkboxes
    7. Creating Radio Buttons
    8. Creating Selection Lists
    9. Dates and Times
    10. Creating Helper Methods
    11. Test Your Knowledge
      1. Quiz
      2. Answers
  10. 7. Strengthening Models with Validation
    1. Without Validation
    2. The Original Model
    3. The Power of Declarative Validation
    4. Managing Secrets
      1. Customizing the Message
      2. Limiting Choices
      3. Testing Format with Regular Expressions
      4. Seen It All Before
      5. Numbers Only
    5. A Place on the Calendar
      1. Testing for Presence
    6. Beyond Simple Declarations
      1. Test It Only If
      2. Do It Yourself
    7. Test Your Knowledge
      1. Quiz
      2. Answers
  11. 8. Improving Forms
    1. Adding a Picture by Uploading a File
      1. File Upload Forms
      2. Model and Migration Changes
        1. A migration for an extension
        2. attr_accessible, again
        3. Extending a model beyond the database
        4. Showing it off
      3. Results
    2. Standardizing Your Look with Form Builders
      1. Supporting Your Own Field Types
      2. Adding Automation
      3. Integrating Form Builders and Styles
    3. Test Your Knowledge
      1. Quiz
      2. Answers
  12. 9. Developing Model Relationships
    1. Connecting Awards to Students
      1. Establishing the Relationship
      2. Supporting the Relationship
      3. Guaranteeing a Relationship
    2. Connecting Students to Awards
      1. Removing Awards When Students Disappear
      2. Counting Awards for Students
    3. Nesting Awards in Students
      1. Changing the Routing
      2. Changing the Controller
      3. Changing the Award Views
      4. Connecting the Student Views
      5. Is Nesting Worth It?
    4. Many-to-Many: Connecting Students to Courses
      1. Creating Tables
      2. Connecting the Models
      3. Adding to the Controllers
      4. Adding Routing
      5. Supporting the Relationship Through Views
        1. Establishing navigation
        2. Showing counts
        3. Enrolling students in courses
    5. What’s Missing?
    6. Test Your Knowledge
      1. Quiz
      2. Answers
  13. 10. Managing Databases with Migrations
    1. What Migrations Offer You
    2. Migration Basics
      1. Migration Files
      2. Running Migrations Forward and Backward
    3. Inside Migrations
      1. Working with Tables
      2. Data Types
      3. Working with Columns
      4. Indexes
      5. Other Opportunities
    4. Test Your Knowledge
      1. Quiz
      2. Answers
  14. 11. Debugging
    1. Creating Your Own Debugging Messages
    2. Raising Exceptions
    3. Logging
    4. Working with Rails from the Console
    5. The Ruby Debugger
    6. Test Your Knowledge
      1. Quiz
      2. Answers
  15. 12. Testing
    1. Test Mode
    2. Setting Up a Test Database with Fixtures
    3. Unit Testing
    4. Functional Testing
      1. Calling Controllers
      2. Testing Responses
      3. Dealing with Nested Resources
    5. Integration Testing
    6. Beyond the Basics
    7. Test Your Knowledge
      1. Quiz
      2. Answers
  16. 13. Sessions and Cookies
    1. Getting Into and Out of Cookies
    2. Storing Data Between Sessions
    3. Test Your Knowledge
      1. Quiz
      2. Answers
  17. 14. Users and Authentication
    1. Installation
    2. Storing Identities
    3. Storing User Data
    4. Wiring OmniAuth into the Application
    5. Classifying Users
    6. More Options
    7. Test Your Knowledge
      1. Quiz
      2. Answers
  18. 15. Routing
    1. Creating Routes to Interpret URIs
      1. Specifying Routes with match
      2. Globbing
      3. Regular Expressions and Routing
      4. A Domain Default with root
      5. Named Routes
      6. Mapping Resources
      7. Nesting Resources
      8. Route Order and Priority
      9. Checking the Map
    2. Generating URIs from Views and Controllers
      1. Pointing url_for in the Right Direction
      2. Adding Options
    3. Infinite Possibilities
    4. Test Your Knowledge
      1. Quiz
      2. Answers
  19. 16. From CSS to SASS
    1. Getting Started
    2. Sassy Style
      1. Variables
      2. Mixins
      3. Nesting
    3. Making Everything Work Together
      1. Becoming Sassier
    4. Test Your Knowledge
      1. Quiz
      2. Answers
  20. 17. Managing Assets and Bundles
    1. The Junk Drawer
      1. Sprockets
      2. Dissecting The Pipeline
      3. Putting It All Together
      4. Bundler
    2. Test Your Knowledge
      1. Quiz
      2. Answers
  21. 18. Sending Code to the Browser: JavaScript and CoffeeScript
    1. Sending JavaScript to the Browser
    2. Simplifying with CoffeeScript
      1. Have Some Sugar with your CoffeeScript
      2. Converting to CoffeeScript
    3. Test Your Knowledge
      1. Quiz
      2. Answers
  22. 19. Mail in Rails
    1. Sending Mail Messages
    2. Receiving Mail
      1. Setup
      2. Processing Messages
    3. Test Your Knowledge
      1. Quiz
      2. Answers
  23. 20. Pushing Further into Rails
    1. Changing to Production Mode
    2. Deploying Is Much More Than Programming
    3. Joining the Rails Ecosystem
      1. Keep Up with Rails
      2. Ruby
      3. Working With and Around Rails
      4. Keep Exploring
  24. A. An Incredibly Brief Introduction to Ruby
    1. How Ruby Works
    2. How Rails Works
    3. Getting Started with Classes and Objects
    4. Comments
    5. Variables, Methods, and Attributes
      1. Variables
        1. Arrays and hashes
        2. Symbols
      2. Methods
        1. Privacy, please
        2. super
        3. Calling methods: advanced options
      3. Attributes
    6. Logic and Conditionals
      1. Operators
      2. if, else, unless, and elsif
      3. ?:
      4. case and when
      5. Loops
        1. while and until
        2. Just Counting
        3. for
      6. Many More Possibilities
  25. B. An Incredibly Brief Introduction to Relational Databases
    1. Tables of Data
      1. Connecting Tables
      2. Using Tables to Connect Tables
      3. Granularity
    2. Databases, Tables, and Rails
  26. C. An Incredibly Brief Guide to Regular Expressions
    1. What Regular Expressions Do
    2. Starting Small
    3. The Simplest Expressions: Literal Strings
    4. Character Classes
    5. Escaping
    6. Modifiers
    7. Anchors
    8. Sequences, Repetition, Groups, and Choices
    9. Greed
    10. More Possibilities
  27. D. Glossary
    1. Speaking in Rails
  28. Index
  29. About the Authors
  30. Colophon
  31. Copyright

Product information

  • Title: Learning Rails 3
  • Author(s): Simon St. Laurent, Edd Dumbill, Eric J Gruber
  • Release date: July 2012
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781449343439