O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Ruby on Rails: Up and Running

Book Description

Ruby on Rails is the super-productive new way to develop full-featuredweb applications. With Ruby on Rails, powerful web applications thatonce took weeks or months to develop can now be produced in a matter ofdays. If it sounds too good to be true, it isn't.

If you're like a lot of web developers, you've probably consideredkicking the tires on Rails - the framework of choice for the newgeneration of Web 2.0 developers. Ruby on Rails: Up and Running takes you out for a test drive and shows you just how fastRuby on Rails can go.

This compact guide teaches you the basics of installing and using boththe Ruby scripting language and the Rails framework for the quickdevelopment of web applications. Ruby on Rails: Up andRunning covers just about everything youneed - from making a simple database-backed application toadding elaborate Ajaxian features and all the juicy bits in between.While Rails is praised for its simplicity and speed of development,there are still a few steps to master on the way. More advancedmaterial helps you map data to an imperfect table, traverse complexrelationships, and build custom finders. A section on working with Ajaxand REST shows you how to exploit the Rails service frameworks to sendemails, implement web services, and create dynamic user-centric webpages. The book also explains the essentials of logging to findperformance problems and delves into other performance-optimizingtechniques.

As new web development frameworks go, Ruby on Rails is the talk of thetown. And Ruby on Rails: Up and Running can makesure you're in on the discussion.

Table of Contents

  1. A Note Regarding Supplemental Files
  2. Preface
    1. Who Should Read This Book?
    2. Conventions Used in This Book
    3. Using Code Examples
    4. Platforms
    5. Safari® Enabled
    6. How to Contact Us
    7. Acknowledgments
  3. 1. Zero to Sixty: Introducing Rails
    1. 1.1. Rails Strengths
    2. 1.2. Putting Rails into Action
    3. 1.3. Organization
    4. 1.4. The Web Server
      1. 1.4.1. Choosing a Server
        1. 1.4.1.1. WEBrick
        2. 1.4.1.2. Apache
        3. 1.4.1.3. lighttpd
        4. 1.4.1.4. Mongrel
        5. 1.4.1.5. Other web servers
    5. 1.5. Creating a Controller
      1. 1.5.1. Running the Controller
    6. 1.6. Building a View
    7. 1.7. Tying the Controller to the View
      1. 1.7.1. Expressions and Scriptlets
    8. 1.8. Under the Hood
    9. 1.9. What’s Next?
  4. 2. Active Record Basics
    1. 2.1. Active Record Basics
      1. 2.1.1. Wrapping, Not Mapping
      2. 2.1.2. A Brief Example
      3. 2.1.3. The Secret Sauce
    2. 2.2. Introducing Photo Share
      1. 2.2.1. Defining the Model
      2. 2.2.2. Configuring Active Record
    3. 2.3. Schema Migrations
    4. 2.4. Basic Active Record Classes
      1. 2.4.1. Wrapping the Table
      2. 2.4.2. The Rails Console
    5. 2.5. Attributes
      1. 2.5.1. Columns
      2. 2.5.2. Accessors
      3. 2.5.3. Identifiers
    6. 2.6. Complex Classes
      1. 2.6.1. Inheritance
      2. 2.6.2. Composition
    7. 2.7. Behavior
      1. 2.7.1. Finders
      2. 2.7.2. Validation
      3. 2.7.3. Transactions
    8. 2.8. Moving Forward
  5. 3. Active Record Relationships
    1. 3.1. belongs_to
    2. 3.2. has_many
    3. 3.3. has_one
      1. 3.3.1. has_and_belongs_to_many
        1. 3.3.1.1. Join models
      2. 3.3.2. acts_as_list
      3. 3.3.3. Trees
    4. 3.4. What You Haven’t Seen
    5. 3.5. Looking Ahead
  6. 4. Scaffolding
    1. 4.1. Using the Scaffold Method
      1. 4.1.1. A List of Photos
      2. 4.1.2. More Metaprogramming
    2. 4.2. Replacing Scaffolding
      1. 4.2.1. Scaffolding Is Dynamic
      2. 4.2.2. Pros and Cons
    3. 4.3. Generating Scaffolding Code
      1. 4.3.1. Inside the Generated Code
      2. 4.3.2. The Best of Both Worlds
    4. 4.4. Moving Forward
  7. 5. Extending Views
    1. 5.1. The Big Picture
    2. 5.2. Seeing Real Photos
    3. 5.3. View Templates
      1. 5.3.1. Layouts
    4. 5.4. Setting the Default Root
    5. 5.5. Stylesheets
    6. 5.6. Hierarchical Categories
      1. 5.6.1. Assign a Category to a Photo
    7. 5.7. Styling the Slideshows
      1. 5.7.1. Creating Your Own Helper Functions
      2. 5.7.2. Creating the Stylesheet
  8. 6. Ajax
    1. 6.1. How Rails Implements Ajax
    2. 6.2. Playing a Slideshow
    3. 6.3. Using Drag-and-Drop to Reorder Slides
    4. 6.4. Drag and Drop Everything (Almost Everything)
    5. 6.5. Filtering by Category
  9. 7. Testing
    1. 7.1. Background
    2. 7.2. Ruby’s Test::Unit
    3. 7.3. Testing in Rails
      1. 7.3.1. Unit Tests, Functional Tests, and Integration Tests
        1. 7.3.1.1. Environments
        2. 7.3.1.2. Fixtures
        3. 7.3.1.3. Unit tests
        4. 7.3.1.4. Functional tests
        5. 7.3.1.5. Integration tests
      2. 7.3.2. Advanced Testing
        1. 7.3.2.1. ZenTest
        2. 7.3.2.2. Selenium
    4. 7.4. Wrapping Up
  10. A. Installing Rails
    1. 1.1. Windows
      1. 1.1.1. Instant Rails
      2. 1.1.2. RadRails
    2. 2.1. OS X
      1. 2.1.1. TextMate and RadRails
    3. 3.1. Linux
  11. B. Quick Reference
    1. 5.1. General
      1. 5.1.1. Documentation
      2. 5.1.2. Supported Web Servers
      3. 5.1.3. Supported Databases
      4. 5.1.4. Integrated Development Environments (IDEs)
        1. 5.1.4.1. Open Source
        2. 5.1.4.2. Commercial
        3. 5.1.4.3. Editors
        4. 5.1.4.4. Debugging
      5. 5.1.5. Create a New Rails Application
    2. 5.2. Testing
      1. 5.2.1. Unit Tests
      2. 5.2.2. Functional Tests
        1. 5.2.2.1. Requests
        2. 5.2.2.2. Redirects
        3. 5.2.2.3. Rendered with Template
        4. 5.2.2.4. Variable Assignments
        5. 5.2.2.5. Rendering of Specific Tags
      3. 5.2.3. Integration Tests
      4. 5.2.4. More on Testing
        1. 5.2.4.1. rake
      5. 5.2.5. Scripts
      6. 5.2.6. Generators
      7. 5.2.7. Plug-ins
    3. 5.3. RJS (Ruby JavaScript)
    4. 5.4. Active Record
      1. 5.4.1. Automated Mapping
      2. 5.4.2. Associations
      3. 5.4.3. Association Join Models (Figure B-3)
      4. 5.4.4. Validations
      5. 5.4.5. Calculations
      6. 5.4.6. Finders
        1. 5.4.6.1. Dynamic attribute-based finders
        2. 5.4.6.2. Scope
      7. 5.4.7. Acts
      8. 5.4.8. Callbacks
      9. 5.4.9. Observers
      10. 5.4.10. Migration
    5. 5.5. Controllers
      1. 5.5.1. Controller Methods
      2. 5.5.2. Render
      3. 5.5.3. Action
      4. 5.5.4. Partials
      5. 5.5.5. Templates
      6. 5.5.6. Files
      7. 5.5.7. Text
      8. 5.5.8. Inline Template
      9. 5.5.9. RJS
      10. 5.5.10. Change content_type
      11. 5.5.11. Redirects
      12. 5.5.12. Nothing
      13. 5.5.13. URL Routing
      14. 5.5.14. Filter
      15. 5.5.15. Session/Flash
        1. 5.5.15.1. Session management
      16. 5.5.16. Cookies
        1. 5.5.16.1. Setting
        2. 5.5.16.2. Reading
        3. 5.5.16.3. Deleting
    6. 5.6. Views
      1. 5.6.1. View Templates
      2. 5.6.2. RHTML
      3. 5.6.3. RXML
      4. 5.6.4. RJS
      5. 5.6.5. Helpers
      6. 5.6.6. Links
      7. 5.6.7. HTML Forms
        1. 5.6.7.1. Form
        2. 5.6.7.2. Text Fields
        3. 5.6.7.3. Text Area
        4. 5.6.7.4. Radio Button
        5. 5.6.7.5. Checkbox
        6. 5.6.7.6. Options
        7. 5.6.7.7. Date and Time
        8. 5.6.7.8. end_form Tag
      8. 5.6.8. Layouts
      9. 5.6.9. Partials
    7. 5.7. Ajax
      1. 5.7.1. Linking to Remote Action
      2. 5.7.2. Callbacks
      3. 5.7.3. Ajax Forms
      4. 5.7.4. Autocompleting Text Field
      5. 5.7.5. Observe Field
      6. 5.7.6. Observe Form
      7. 5.7.7. periodically_call_remote
    8. 5.8. Configuring Your Application
      1. 5.8.1. Session Configuration
      2. 5.8.2. Caching Configuration
  12. Index
  13. About the Authors
  14. Colophon
  15. Copyright