The definitive, Jolt-award winning guide to learning and using Rails is now in its Second Edition. Rails is a new approach to web-based application development that enables developers to create full-featured, sophisticated web-based applications using less code and less effort. Now programmers can get the job done right and still leave work on time.
NEW IN THE SECOND EDITION: The book has been updated to take advantage of all the new Rails 1.2 features. The sample application uses migrations, Ajax, features a REST interface, and illustrates new Rails features. There are new chapters on migrations, active support, active record, and action controller (including the new resources-based routing). The Web 2.0 and Deployment chapters have been completely rewritten to reflect the latest thinking. Now you can learn which environments are best for your style application, and see how Capistrano makes managing your site simple. All the remaining chapters have been extensively updated. Finally, hundreds of comments from readers of the first edition have been incorporated, making this book simply the best available.
Rails is a full-stack, open source web framework that enables you to create full-featured, sophisticated web-based applications with a twist...you can create a full Rails application using less code than the setup XML you'd need just to configure some other frameworks.
With this book, you'll learn how to use Rails Active Record to connect business objects and database tables. No more painful object-relational mapping. Just create your business objects and let Rails do the rest. You'll learn how to use the Action Pack framework to route incoming requests and render pages using easy-to-write templates and components. See how to exploit the Rails service frameworks to send emails, talk to web services, and interact dynamically with JavaScript applications running in the browser (the ''Ajax'' architecture).
You'll see how easy it is to deploy Rails. You'll be writing applications that work with your favorite database (MySQL, Oracle, Postgres, and more) in no time at all.
Contents......Page 5
Preface to the Second Edition......Page 12
Introduction......Page 14
Rails Is Agile......Page 16
Finding Your Way Around......Page 17
Acknowledgments......Page 19
Getting Started......Page 21
Models, Views, and Controllers......Page 22
Active Record: Rails Model Support......Page 25
Action Pack: The View and Controller......Page 29
Your Shopping List......Page 31
Installing on Windows......Page 32
Installing on Mac OS X......Page 34
Installing on Linux......Page 35
Development Environments......Page 36
Rails and Databases......Page 39
Rails and ISPs......Page 42
Creating a New Application......Page 43
Hello, Rails!......Page 45
Linking Pages Together......Page 56
What We Just Did......Page 59
Building an Application......Page 61
Incremental Development......Page 62
What Depot Does......Page 63
Let's Code......Page 67
Iteration A1: Get Something Running......Page 68
Iteration A2: Add a Missing Column......Page 79
Iteration A3: Validate!......Page 81
Iteration A4: Prettier Listings......Page 85
Iteration B1: Create the Catalog Listing......Page 94
Iteration B2: Add a Page Layout......Page 97
Iteration B3: Use a Helper to Format the Price......Page 99
Iteration B4: Linking to the Cart......Page 100
Sessions......Page 104
Iteration C1: Creating a Cart......Page 107
Iteration C2: A Smarter Cart......Page 110
Iteration C3: Handling Errors......Page 113
Iteration C4: Finishing the Cart......Page 118
Task D: Add a Dash of AJAX......Page 122
Iteration D1: Moving the Cart......Page 123
Iteration D2: An AJAX-Based Cart......Page 127
Iteration D3: Highlighting Changes......Page 131
Iteration D4: Hide an Empty Cart......Page 133
Iteration D5: Degrading If Javascript Is Disabled......Page 137
What We Just Did......Page 138
Iteration E1: Capturing an Order......Page 140
Iteration F1: Adding Users......Page 155
Iteration F2: Logging In......Page 163
Iteration F3: Limiting Access......Page 166
Iteration F4: A Sidebar, More Administration......Page 168
Generating the XML Feed......Page 174
Finishing Up......Page 181
Tests Baked Right In......Page 184
Unit Testing of Models......Page 185
Functional Testing of Controllers......Page 197
Integration Testing of Applications......Page 212
Performance Testing......Page 220
Using Mock Objects......Page 224
The Rails Framework......Page 227
Directory Structure......Page 228
Rails Configuration......Page 236
Naming Conventions......Page 240
Logging in Rails......Page 243
Debugging Hints......Page 244
What's Next......Page 246
Generally Available Extensions......Page 247
Enumerations and Arrays......Page 248
String Extensions......Page 249
Extensions to Numbers......Page 251
Time and Date Extensions......Page 252
An Extension to Ruby Symbols......Page 254
with_options......Page 255
Unicode Support......Page 256
Migrations......Page 262
Creating and Running Migrations......Page 263
Anatomy of a Migration......Page 265
Managing Tables......Page 269
Data Migrations......Page 274
Advanced Migrations......Page 277
When Migrations Go Bad......Page 279
Schema Manipulation Outside Migrations......Page 280
Managing Migrations......Page 281
Active Record: The Basics......Page 283
Columns and Attributes......Page 284
Primary Keys and IDs......Page 288
Connecting to the Database......Page 290
CRUD---Create, Read, Update, Delete......Page 295
Aggregation and Structured Data......Page 313
Miscellany......Page 320
Active Record: Relationships between Tables......Page 323
Creating Foreign Keys......Page 324
Specifying Relationships in Models......Page 326
belongs_to and has_xxx Declarations......Page 328
Joining to Multiple Tables......Page 343
Self-referential Joins......Page 353
Acts As......Page 354
When Things Get Saved......Page 358
Preloading Child Rows......Page 360
Counters......Page 361
Validation......Page 363
Callbacks......Page 373
Advanced Attributes......Page 380
Transactions......Page 383
The Basics......Page 392
Routing Requests......Page 393
Action Methods......Page 424
Cookies and Sessions......Page 435
Flash---Communicating between Actions......Page 445
Filters and Verification......Page 447
Caching, Part One......Page 455
The Problem with GET Requests......Page 462
Templates......Page 465
Using Helpers......Page 471
Helpers for Formatting, Linking, and Pagination......Page 472
How Forms Work......Page 480
Forms That Wrap Model Objects......Page 482
Custom Form Builders......Page 494
Working with Nonmodel Fields......Page 498
Uploading Files to Rails Applications......Page 501
Layouts and Components......Page 505
Caching, Part Two......Page 513
Adding New Templating Systems......Page 518
Prototype......Page 521
Script.aculo.us......Page 542
RJS Templates......Page 558
Conclusion......Page 565
Sending E-mail......Page 567
Receiving E-mail......Page 577
Testing E-mail......Page 579
What AWS Is (and What It Isn't)......Page 583
The API Definition......Page 584
Dispatching Modes......Page 589
Using Alternate Dispatching......Page 590
Method Invocation Interception......Page 592
Testing Web Services......Page 594
Protocol Clients......Page 597
Secure and Deploy Your Application......Page 598
SQL Injection......Page 599
Creating Records Directly from Form Parameters......Page 601
Don't Trust ID Parameters......Page 603
Don't Expose Controller Methods......Page 604
Cross-Site Scripting (CSS/XSS)......Page 605
Avoid Session Fixation Attacks......Page 607
File Uploads......Page 608
Don't Store Sensitive Information in the Clear......Page 609
Use SSL to Transmit Sensitive Information......Page 610
Knowing That It Works......Page 611
Deployment and Production......Page 613
Starting Early......Page 614
How a Production Server Works......Page 615
Comparing Front-End Web Servers......Page 617
Repeatable Deployments with Capistrano......Page 618
Setting Up a Deployment Environment......Page 619
Checking Up on a Deployed Application......Page 625
Production Application Chores......Page 626
Moving On to Launch and Beyond......Page 627
Appendices......Page 629
Ruby Is an Object-Oriented Language......Page 630
Ruby Names......Page 631
Methods......Page 632
Classes......Page 634
Modules......Page 636
Arrays and Hashes......Page 637
Control Structures......Page 638
Blocks and Iterators......Page 639
Exceptions......Page 640
Ruby Idioms......Page 641
RDoc Documentation......Page 643
Top-Level Configuration......Page 644
Active Record Configuration......Page 646
Action Controller Configuration......Page 648
Action View Configuration......Page 649
Action Mailer Configuration......Page 650
Test Case Configuration......Page 651
The Full Depot Application......Page 652
Bibliography......Page 683
A......Page 684
B......Page 689
C......Page 690
D......Page 692
E......Page 695
F......Page 696
H......Page 697
I......Page 698
L......Page 699
M......Page 700
N......Page 701
P......Page 702
R......Page 705
S......Page 708
T......Page 710
V......Page 712
W......Page 713
Z......Page 714