You want to write professional-grade applications: Rails is a full-stack, open-source web framework, with integrated support for unit, functional, and integration testing. It enforces good design principles, consistency of code across your team (and across your organization), and proper release management. But Rails is more than a set of best practices. Rails makes it both fun and easy to turn out very cool web applications. Need Ajax support, so your web applications are highly interactive? Rails has it built in. Want an application that sends and receives e-mail? Built in. Supports internationalization and localization? Built in. Do you need applications with a REST-based interface (so they can interact with other RESTful applications with almost no effort on your part)? All built-in. With this book, you'll learn how to use ActiveRecord to connect business objects and database tables. No more painful object-relational mapping. Just create your business objects and let Rails do the rest. Need to create and modify your schema? Migrations make it painless (and they're versioned, so you can roll changes backward and forward). 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, implement web services, and create dynamic, user-centric web-pages using built-in Javascript and Ajax support. There is extensive coverage of testing, and the rewritten Deployment chapter now covers Phusion Passenger. As with the previous editions of the book, we start with an extended tutorial that builds parts of an online store. And, of course, the application has been rewritten to show the best of Rails V2.
Author(s): Sam Ruby, Dave Thomas, David Heinemeier Hansson
Edition: Third Edition
Publisher: Pragmatic Bookshelf
Year: 2009
Language: English
Pages: 766
Contents......Page 5
Preface to the Second Edition......Page 11
Preface to the Third Edition......Page 13
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
Installing on Windows......Page 31
Installing on Mac OS X......Page 33
Installing on Linux......Page 34
Development Environments......Page 36
Rails and Databases......Page 40
Rails and ISPs......Page 42
Creating a New Application......Page 44
Hello, Rails!......Page 46
Linking Pages Together......Page 57
What We Just Did......Page 61
Building an Application......Page 62
Incremental Development......Page 63
What Depot Does......Page 64
Let's Code......Page 68
Iteration A1: Getting Something Running......Page 69
Creating the Products Model and Maintenance Application......Page 75
Iteration A2: Adding a Missing Column......Page 79
Iteration A3: Validating!......Page 85
Iteration A4: Making Prettier Listings......Page 89
Iteration B1: Creating the Catalog Listing......Page 95
Iteration B2: Adding a Page Layout......Page 99
Iteration B3: Using a Helper to Format the Price......Page 101
Iteration B4: Linking to the Cart......Page 102
Sessions......Page 105
Iteration C1: Creating a Cart......Page 109
Iteration C2: Creating a Smarter Cart......Page 112
Iteration C3: Handling Errors......Page 115
Iteration C4: Finishing the Cart......Page 120
Task D: Add a Dash of Ajax......Page 124
Iteration D1: Moving the Cart......Page 125
Iteration D2: Creating an Ajax-Based Cart......Page 130
Iteration D3: Highlighting Changes......Page 133
Iteration D4: Hiding an Empty Cart......Page 136
Iteration D5: Degrading If Javascript Is Disabled......Page 139
What We Just Did......Page 140
Iteration E1: Capturing an Order......Page 142
Iteration F1: Adding Users......Page 159
Iteration F2: Logging In......Page 168
Iteration F3: Limiting Access......Page 171
Iteration F4: Adding a Sidebar, More Administration......Page 174
Generating the XML Feed......Page 181
Finishing Up......Page 191
Iteration I1: Enabling Translation......Page 193
Iteration I2: Exploring Strategies for Content......Page 207
Tests Baked Right In......Page 210
Unit Testing of Models......Page 211
Functional Testing of Controllers......Page 224
Integration Testing of Applications......Page 240
Performance Testing......Page 249
Using Mock Objects......Page 253
Working with the Rails Framework......Page 256
Directory Structure......Page 257
Rails Configuration......Page 264
Naming Conventions......Page 268
Debugging Hints......Page 272
What's Next......Page 274
Generally Available Extensions......Page 275
Enumerations and Arrays......Page 276
String Extensions......Page 278
Extensions to Numbers......Page 281
Time and Date Extensions......Page 282
with_options......Page 284
Unicode Support......Page 285
Migrations......Page 291
Creating and Running Migrations......Page 293
Anatomy of a Migration......Page 295
Managing Tables......Page 299
Data Migrations......Page 304
Advanced Migrations......Page 307
When Migrations Go Bad......Page 311
Schema Manipulation Outside Migrations......Page 312
Managing Migrations......Page 313
Active Record: The Basics......Page 315
Columns and Attributes......Page 316
Primary Keys and ids......Page 320
Connecting to the Database......Page 322
Create, Read, Update, Delete (CRUD)......Page 327
Aggregation and Structured Data......Page 346
Miscellany......Page 353
Active Record: Relationships Between Tables......Page 357
Creating Foreign Keys......Page 358
Specifying Relationships in Models......Page 360
belongs_to and has_xxx Declarations......Page 362
Joining to Multiple Tables......Page 377
Self-referential Joins......Page 387
Acts As......Page 388
When Things Get Saved......Page 392
Preloading Child Rows......Page 394
Counters......Page 395
Validation......Page 397
Callbacks......Page 407
Advanced Attributes......Page 414
Transactions......Page 418
The Basics......Page 425
Routing Requests......Page 426
Resource-Based Routing......Page 441
Testing Routing......Page 458
Action Methods......Page 461
Cookies and Sessions......Page 473
Flash: Communicating Between Actions......Page 486
Filters and Verification......Page 488
Caching, Part One......Page 496
The Problem with GET Requests......Page 505
Templates......Page 508
Using Helpers......Page 514
Helpers for Formatting, Linking, and Pagination......Page 515
How Forms Work......Page 523
Forms That Wrap Model Objects......Page 524
Custom Form Builders......Page 537
Working with Nonmodel Fields......Page 541
Uploading Files to Rails Applications......Page 544
Layouts and Components......Page 548
Caching, Part Two......Page 555
Adding New Templating Systems......Page 560
Prototype......Page 563
Script.aculo.us......Page 583
RJS Templates......Page 600
Conclusion......Page 607
Sending E-mail......Page 609
Receiving E-mail......Page 620
Testing E-mail......Page 622
Alternatives to Active Resource......Page 625
Show Me the Code!......Page 628
Relationships and Collections......Page 631
Pulling It All Together......Page 634
Securing and Deploying Your Application......Page 636
SQL Injection......Page 637
Creating Records Directly from Form Parameters......Page 640
Don't Trust id Parameters......Page 641
Don't Expose Controller Methods......Page 642
Cross-Site Scripting (CSS/XSS)......Page 643
File Uploads......Page 646
Don't Store Sensitive Information in the Clear......Page 647
Use SSL to Transmit Sensitive Information......Page 648
Knowing That It Works......Page 650
Starting Early......Page 651
How a Production Server Works......Page 652
Installing Passenger......Page 655
Worry-Free Deployment with Capistrano......Page 657
Checking Up on a Deployed Application......Page 661
Production Application Chores......Page 662
Moving On to Launch and Beyond......Page 664
Appendixes......Page 665
Ruby Is an Object-Oriented Language......Page 666
Ruby Names......Page 667
Methods......Page 668
Classes......Page 670
Modules......Page 672
Arrays and Hashes......Page 673
Control Structures......Page 674
Blocks and Iterators......Page 675
Exceptions......Page 676
Ruby Idioms......Page 677
RDoc Documentation......Page 679
Top-Level Configuration......Page 680
Active Record Configuration......Page 682
Action Controller Configuration......Page 684
Action Mailer Configuration......Page 686
Test Case Configuration......Page 688
The Full Depot Application......Page 689
Online Resources......Page 727
A......Page 729
C......Page 736
D......Page 740
E......Page 743
F......Page 744
G......Page 745
H......Page 746
I......Page 747
L......Page 748
M......Page 749
N......Page 750
P......Page 751
Q......Page 754
R......Page 755
S......Page 758
T......Page 760
V......Page 763
X......Page 764
Z......Page 765