Raleigh, North Carolina Dallas, Texas
Contents
1 Introduction 1
A.1 Ruby Is an Object-Oriented Language
A.2 Ruby Names
A.3 Methods
A.4 Classes
A.5 Modules
A.6 Arrays and Hashes
A.7 Control Structures
A.8 Regular Expressions
A.9 Blocks and Iterators
A.10 Exceptions
A.11 Marshaling Objects
A.12 Interactive Ruby
A.13 Ruby Idioms
A.14 RDoc Documentation
B Configuration Parameters 482
B.1 Active Record Configuration
B.2 Action Pack Configuration
B.3 Action Mailer Configuration
B.4 Test Case Configuration
C Source Code 486
C.1 The Full Depot Application
C.2 Sample System Notifier
C.3 Cross-Reference of Code Samples
D Resources 516
D.1 Online Resources
D.2 Bibliography
1.1 Rails Is Agile
1.2 Finding Your Way Around
1.3 Acknowledgments
Part I—Getting Started 8
2 The Architecture of Rails Applications 9
2.1 Models, Views, and Controllers
2.2 Active Record: Rails Model Support
2.3 Action Pack: The View and Controller
3 Installing Rails 19
3.1 Installing on Windows
3.2 Installing on Mac OS X
3.3 Installing on Unix/Linux
3.4 Rails and Databases
3.5 Keeping Up-to-Date
3.6 Rails and ISPs
4 Instant Gratification 25
4.1 Creating a New Application
4.2 Hello, Rails!
4.3 Linking Pages Together
4.4 What We Just Did
Part II—Building an Application 42
5 The Depot Application 43
5.1 Incremental Development
5.2 What Depot Does
5.3 Let’s Code
6 Task A: Product Maintenance 49
6.1 Iteration A1: Get Something Running
6.2 Iteration A2: Add a Missing Column
6.3 Iteration A3: Validate!
6.4 Iteration A4: Prettier Listings
7 Task B: Catalog Display 67
7.1 Iteration B1: Create the Catalog Listing
7.2 Iteration B2: Add Page Decorations
8 Task C: Cart Creation 74
8.1 Sessions
8.2 More Tables, More Models
8.3 Iteration C1: Creating a Cart
8.4 Iteration C2: Handling Errors
8.5 Iteration C3: Finishing the Cart
9 Task D: Checkout! 95
9.1 Iteration D1: Capturing an Order
9.2 Iteration D2: Show Cart Contents on Checkout
10 Task E: Shipping 109
10.1 Iteration E1: Basic Shipping
11 Task F: Administrivia 118
11.1 Iteration F1: Adding Users
11.2 Iteration F2: Logging In
11.3 Iteration F3: Limiting Access
11.4 Finishing Up
11.5 More Icing on the Cake
12 Task T: Testing 132
12.1 Tests Baked Right In
12.2 Testing Models
12.3 Testing Controllers
12.4 Using Mock Objects
12.5 Test-Driven Development
12.6 Running Tests with Rake
12.7 Performance Testing
Part III—The Rails Framework 172
13 Rails in Depth 173
13.1 So Where’s Rails?
13.2 Directory Structure
13.3 Rails Configuration
13.4 Naming Conventions
13.5 Active Support
13.6 Logging in Rails
13.7 Debugging Hints
13.8 What’s Next
14 Active Record Basics 190
14.1 Tables and Classes
14.2 Columns and Attributes
14.3 Primary Keys and IDs
14.4 Connecting to the Database
14.5 CRUD—Create, Read, Update, Delete
14.6 Relationships between Tables
14.7 Transactions
15 More Active Record 243
15.1 Acts As
15.2 Aggregation
15.3 Single Table Inheritance
15.4 Validation
15.5 Callbacks
15.6 Advanced Attributes
15.7 Miscellany
16 Action Controller and Rails 278
16.1 Context and Dependencies
16.2 The Basics
16.3 Routing Requests
16.4 Action Methods
16.5 Cookies and Sessions
16.6 Flash—Communicating between Actions
16.7 Filters and Verification
16.8 Caching, Part One
16.9 The Problem with GET Requests
17 Action View 327
17.1 Templates
17.2 Builder templates
17.3 RHTML Templates
17.4 Helpers
17.5 Formatting Helpers
17.6 Linking to Other Pages and Resources
17.7 Pagination
17.8 Form Helpers
17.9 Layouts and Components
17.10 Caching, Part Two
17.11 Adding New Templating Systems
18 The Web, V2.0 373
18.1 Introducing AJAX
18.2 The Rails Way
18.3 The User Interface, Revisited
18.4 Advanced Techniques
19 Action Mailer 399
19.1 Sending E-mail
19.2 Receiving E-mail
19.3 Testing E-mail
20 Web Services on Rails 411
20.1 What AWS Is (and What It Isn’t)
20.2 The API Definition
20.3 Dispatching Modes
20.4 Using Alternate Dispatching
20.5 Method Invocation Interception
20.6 Testing Web Services
20.7 Protocol Clients
21 Securing Your Rails Application 427
21.1 SQL Injection
21.2 Cross-Site Scripting (CSS/XSS)
21.3 Avoid Session Fixation Attacks
21.4 Creating Records Directly from Form Parameters
21.5 Don’t Trust ID Parameters
21.6 Don’t Expose Controller Methods
21.7 File Uploads
21.8 Don’t Cache Authenticated Pages
21.9 Knowing That It Works
22 Deployment and Scaling 440
22.1 Picking a Production Platform
22.2 A Trinity of Environments
22.3 Iterating in the Wild
22.4 Maintenance
22.6 Finding and Dealing with Bottlenecks
22.7 Case Studies: Rails Running Daily
Part IV—Appendices 466
A IntroductiontoRuby 467A.1 Ruby Is an Object-Oriented Language
A.2 Ruby Names
A.3 Methods
A.4 Classes
A.5 Modules
A.6 Arrays and Hashes
A.7 Control Structures
A.8 Regular Expressions
A.9 Blocks and Iterators
A.10 Exceptions
A.11 Marshaling Objects
A.12 Interactive Ruby
A.13 Ruby Idioms
A.14 RDoc Documentation
B Configuration Parameters 482
B.1 Active Record Configuration
B.2 Action Pack Configuration
B.3 Action Mailer Configuration
B.4 Test Case Configuration
C Source Code 486
C.1 The Full Depot Application
C.2 Sample System Notifier
C.3 Cross-Reference of Code Samples
D Resources 516
D.1 Online Resources
D.2 Bibliography
● Screenshot ●