Cover image for Rails: Up and Running, 2nd Edition

Book description

In just a matter of days, you can develop powerful web applications with Rails that once took weeks or months to produce with other web frameworks. If that sounds too good to be true, it isn't. Find out for yourself with Rails: Up and Running, the concise and popular book that not only explains how Rails works, but guides you through a complete test drive. Perfect for beginning web developers, this thoroughly revised edition teaches you the basics of installing and using Rails 2.1 and the Ruby scripting language. While Rails is praised for its simplicity, there are still a few tricky steps to master along the way. Rails: Up and Running offers lots of examples and covers just about everything you need to build functional Rails applications right away. Learn how to:

  • Create simple database-backed applications, and build dynamic user-centric web pages using Ajax and REST

  • Exploit the Rails service frameworks to send emails and implement web services

  • Map data to an imperfect table, traverse complex relationships, and build custom finders

  • Use techniques to solve common database performance problems

See how fast you can go on Rails, and how reliable it's become with the stability and power of version 2.1. With Rails: Up and Running, you'll discover why Rails is a remarkable new way to build database-driven web applications.

Table of Contents

  1. Special Upgrade Offer
  2. A Note Regarding Supplemental Files
  3. Preface
    1. Who Should Read This Book?
    2. Conventions Used in This Book
    3. Using Code Examples
    4. Platforms
    5. Safari® Books Online
    6. How to Contact Us
    7. Acknowledgments
  4. 1. Zero to Sixty: Introducing Rails
    1. Putting Rails into Action
    2. Organization
    3. The Web Server
      1. Choosing a Server
        1. Apache
        2. nginx
        3. Mongrel
        4. WEBrick
        5. Other web servers
    4. Creating a Controller
      1. Mapping params
    5. Building a View
    6. Tying Controller Data to the View
      1. Expressions and Scriptlets
    7. Under the Hood
    8. What’s Next?
  5. 2. Scaffolding, REST, and Routes
    1. Introducing Photo Share
      1. Defining the Resources
    2. Preparing Your Project and Database
    3. Generating a Resource Scaffold
      1. A List of Photos
    4. RESTful Routes
      1. Named Routes
      2. REST
      3. The Controller Code
    5. Wrapping Up the Scaffolding
    6. What’s Next?
  6. 3. Active Record Basics
    1. Active Record Basics
      1. Wrapping, Not Mapping
      2. A Brief Example
    2. Generating Models
    3. Basic Active Record Classes
      1. Wrapping the Table
      2. The Rails Console
    4. Attributes
      1. Columns
      2. Identifiers
    5. Complex Classes
      1. Inheritance
      2. Composition
    6. Behavior
      1. Finders
      2. Validation
      3. Transactions
      4. Conversions
    7. Moving Forward
  7. 4. Active Record Relationships
    1. belongs_to
    2. has_many
    3. has_one
    4. has_and_belongs_to_many
      1. Join Models
    5. acts_as_list
    6. Trees
    7. What You Haven’t Seen
    8. Looking Ahead
  8. 5. Working with Views
    1. The Big Picture
    2. Seeing Real Photos
    3. View Templates
      1. Layouts
    4. Setting the Default Root
    5. Stylesheets
    6. Hierarchical Categories
      1. Assign a Category to a Photo
    7. Styling the Slideshows
      1. Creating Your Own Helper Functions
      2. Creating the Stylesheet
  9. 6. Ajax
    1. How Rails Implements Ajax
    2. Playing a Slideshow
    3. Using Drag-and-Drop to Reorder Slides
    4. Drag-and-Drop Everything (Almost Everything)
    5. Filtering by Category
  10. 7. Testing
    1. Background
    2. Ruby’s Test::Unit
    3. Testing in Rails
      1. Unit Tests, Functional Tests, and Integration Tests
        1. Environments
        2. Fixtures
        3. Unit tests
        4. Functional tests
    4. Test Coverage
    5. Mocking with Mocha
    6. Assertions and Integration Tests
      1. Assertions in Rails
      2. Integration Tests
        1. Selenium
    7. Wrapping Up
  11. A. Installing Rails
    1. Windows
      1. Ruby One-Click Installer
      2. Ruby on Rails
      3. Mongrel
      4. SQLite
      5. RadRails
    2. OS X
      1. TextMate and RadRails
    3. Linux
  12. B. Quick Reference
    1. General
      1. Documentation
      2. Supported Web Servers
      3. Supported Databases
      4. Integrated Development Environments (IDEs)
        1. Open Source
        2. Commercial
        3. Editors
        4. Debugging
      5. Create a New Rails Application
    2. Testing
      1. Unit Tests
      2. Functional Tests
        1. Requests
        2. Redirects
        3. Rendered with template
        4. Variable assignments
        5. Rendering of specific tags
      3. Integration Tests
      4. More on Testing
        1. rake
      5. Generators
      6. Plug-ins
    3. RJS (Ruby JavaScript)
    4. Active Record
      1. Automated Mapping
      2. Associations
      3. Association Join Models (As Shown in Figure B-3)
      4. Validations
      5. Calculations
      6. Finders
        1. Dynamic attribute-based finders
        2. Scope
        3. Named scope
      7. Acts
      8. Callbacks
      9. Observers
      10. Migration
    5. Controllers
      1. REST
        1. Named routes
      2. Controller Methods
      3. Render
      4. Action
      5. Partials
      6. Templates
      7. Files
      8. Text
      9. Inline Template
      10. RJS
      11. Change content_type
      12. Redirects
      13. Nothing
      14. URL Routing
      15. Filter
      16. Session/Flash
        1. Session management
      17. Cookies
        1. Setting
        2. Reading
        3. Deleting
    6. Views
      1. View Templates
      2. html.erb
      3. xml.erb
      4. RJS
      5. Helpers
      6. Links
      7. HTML Forms
        1. Form
        2. Text fields
        3. Text area
        4. Radio button
        5. Checkbox
        6. Options
        7. Date and time
        8. end_form tag
      8. Layouts
      9. Partials
    7. Ajax
      1. Linking to Remote Action
      2. Callbacks
      3. Ajax Forms
      4. Autocompleting Text Field
      5. Observe Field
      6. Observe Form
      7. periodically_call_remote
    8. Configuring Your Application
      1. Session Configuration
      2. Caching Configuration
  13. Index
  14. About the Authors
  15. Colophon
  16. Special Upgrade Offer
  17. Copyright