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. Contents......Page 5 Preface to the Second Edition......Page 12 Preface to the Third Edition......Page 14 Introduction......Page 16 Rails Is Agile......Page 18 Finding Your Way Around......Page 19 Acknowledgments......Page 21 Getting Started......Page 23 Models, Views, and Controllers......Page 24 Active Record: Rails Model Support......Page 27 Action Pack: The View and Controller......Page 31 Installing on Windows......Page 33 Installing on Mac OS X......Page 35 Installing on Linux......Page 36 Development Environments......Page 37 Rails and Databases......Page 41 Keeping Up-to-Date......Page 42 Rails and ISPs......Page 43 Creating a New Application......Page 44 Hello, Rails!......Page 46 Linking Pages Together......Page 57 What We Just Did......Page 60 Building an Application......Page 62 Incremental Development......Page 63 What Depot Does......Page 64 Let's Code......Page 68 Iteration A1: Get Something Running......Page 69 Create the Products Model and Maintenance Application......Page 74 Iteration A2: Add a Missing Column......Page 79 Iteration A3: Validate!......Page 84 Iteration A4: Prettier Listings......Page 88 Iteration B1: Create the Catalog Listing......Page 95 Iteration B2: Add a Page Layout......Page 99 Iteration B4: Linking to the Cart......Page 101 Sessions......Page 105 Iteration C1: Creating a Cart......Page 109 Iteration C2: 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: An AJAX-Based Cart......Page 130 Iteration D3: Highlighting Changes......Page 133 Iteration D4: Hide an Empty Cart......Page 135 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 158 Iteration F2: Logging In......Page 168 Iteration F3: Limiting Access......Page 171 Iteration F4: A Sidebar, More Administration......Page 174 Generating the XML Feed......Page 181 Finishing Up......Page 188 Tests Baked Right In......Page 192 Unit Testing of Models......Page 193 Functional Testing of Controllers......Page 205 Integration Testing of Applications......Page 221 Performance Testing......Page 229 Using Mock Objects......Page 233 The Rails Framework......Page 236 Directory Structure......Page 237 Rails Configuration......Page 244 Naming Conventions......Page 248 Debugging Hints......Page 252 What's Next......Page 254 Generally Available Extensions......Page 256 Enumerations and Arrays......Page 257 String Extensions......Page 258 Extensions to Numbers......Page 260 Time and Date Extensions......Page 261 An Extension to Ruby Symbols......Page 263 with_options......Page 264 Unicode Support......Page 265 Migrations......Page 270 Creating and Running Migrations......Page 272 Anatomy of a Migration......Page 273 Managing Tables......Page 277 Data Migrations......Page 282 Advanced Migrations......Page 285 Schema Manipulation Outside Migrations......Page 289 Managing Migrations......Page 290 Active Record: The Basics......Page 292 Columns and Attributes......Page 293 Primary Keys and IDs......Page 297 Connecting to the Database......Page 299 CRUD---Create, Read, Update, Delete......Page 304 Aggregation and Structured Data......Page 322 Miscellany......Page 329 Active Record: Relationships between Tables......Page 332 Creating Foreign Keys......Page 333 Specifying Relationships in Models......Page 335 belongs_to and has_xxx Declarations......Page 337 Joining to Multiple Tables......Page 352 Self-referential Joins......Page 363 Acts As......Page 364 When Things Get Saved......Page 368 Preloading Child Rows......Page 370 Counters......Page 371 Validation......Page 373 Callbacks......Page 384 Advanced Attributes......Page 391 Transactions......Page 394 The Basics......Page 403 Routing Requests......Page 404 Resource-Based Routing......Page 420 Testing Routing......Page 436 Action Methods......Page 439 Cookies and Sessions......Page 450 Flash---Communicating between Actions......Page 460 Filters and Verification......Page 462 Caching, Part One......Page 470 The Problem with GET Requests......Page 477 Templates......Page 481 Using Helpers......Page 487 Helpers for Formatting, Linking, and Pagination......Page 489 How Forms Work......Page 496 Forms That Wrap Model Objects......Page 498 Custom Form Builders......Page 510 Working with Nonmodel Fields......Page 515 Uploading Files to Rails Applications......Page 518 Layouts and Components......Page 522 Caching, Part Two......Page 530 Adding New Templating Systems......Page 535 Prototype......Page 538 Script.aculo.us......Page 559 RJS Templates......Page 575 Conclusion......Page 582 Sending E-mail......Page 584 Receiving E-mail......Page 595 Testing E-mail......Page 596 What AWS Is (and What It Isn't)......Page 600 The API Definition......Page 601 Dispatching Modes......Page 606 Using Alternate Dispatching......Page 607 Method Invocation Interception......Page 609 Testing Web Services......Page 611 Protocol Clients......Page 614 Secure and Deploy Your Application......Page 615 SQL Injection......Page 616 Creating Records Directly from Form Parameters......Page 618 Don't Trust ID Parameters......Page 620 Don't Expose Controller Methods......Page 621 Cross-Site Scripting (CSS/XSS)......Page 622 Avoid Session Fixation Attacks......Page 624 File Uploads......Page 625 Don't Store Sensitive Information in the Clear......Page 626 Use SSL to Transmit Sensitive Information......Page 627 Knowing That It Works......Page 628 Deployment and Production......Page 630 Starting Early......Page 631 How a Production Server Works......Page 632 Comparing Front-End Web Servers......Page 634 Repeatable Deployments with Capistrano......Page 635 Setting Up a Deployment Environment......Page 636 Checking Up on a Deployed Application......Page 642 Production Application Chores......Page 643 Moving On to Launch and Beyond......Page 645 Appendices......Page 646 Ruby Is an Object-Oriented Language......Page 647 Ruby Names......Page 648 Methods......Page 649 Classes......Page 651 Modules......Page 653 Arrays and Hashes......Page 654 Control Structures......Page 655 Blocks and Iterators......Page 656 Exceptions......Page 657 Ruby Idioms......Page 658 RDoc Documentation......Page 660 Top-Level Configuration......Page 661 Active Record Configuration......Page 663 Action Controller Configuration......Page 665 Action View Configuration......Page 666 Action Mailer Configuration......Page 667 Test Case Configuration......Page 668 The Full Depot Application......Page 669 Online Resources......Page 696 A......Page 697 C......Page 703 D......Page 707 E......Page 709 F......Page 710 H......Page 712 I......Page 713 L......Page 714 M......Page 715 N......Page 716 P......Page 717 R......Page 720 S......Page 723 T......Page 725 U......Page 727 W......Page 728 Z......Page 729 It's a good text, but it might be recommended that an Agile Development specific book be read, either beforehand or concurrently, while evolving the knowledge imparted in these pages. "The Art of Agile Development" by James Shore is a good compliment to this reading. Agile of course, does not only apply to Ruby and Rails, but Ruby and Rails are uniquely fashioned to promote Agile techniques. Prior Rails books do not illuminate this connection so well as this one does, if at all. As such, it can be more highly recommended to learn rails via this book as it exposes this connection through-out. As a context sensitive framework, rails can be learned to the degree of exposing just that much, or ... one might learn how to use rails in an fully iterative and collaborative development environment. That statement should clarify the import of this book. One might claim that there is a right way to learn Rails and well then too, the old way. Learn it the right way, using Agile Development practices. One quickly notes that Agile is not just a management tool, but a programmer's development methodology. In fact it transcends many development functions, from product management to testing, final release and continued maintenance and support. Rails as a framework, is enhanced by an understanding of how it fits with Agile. This book goes miles toward making that clear. [from back cover] Ruby on Rails is a full-stack MVC web framework that helps you produce high-quality, beautiful-looking web applications in less time than you'd think possible. You concentrate on the application, and rails takes care of the details. You can even write JavaScript-enable applications without writing a line of JavaScript code. Rails has Evolved over the years, and this book has evolved along with it. We still start with a step-by-step walkthrough of building a real application, and we still have in-depth chapters looking at the built-in Rails features. But we also now feature a new emphasis on Rails resources and highlight the best-practices used by today's Rails developers. With this book, you'll • Follow along with an extended tutorial as we write a web-based store application; • Learn how Rails eliminates tedious configuration and housekeeping; • Find out how to internationalize your applications; • See how to incorporate Ajax, REST, web services, and e-mail handling into your application; • Test your applications as you write them using the built-in unit, function, and integration-testing frameworks; and • Deploy your applications, easily and securely. This book covers Rails 2—it's a major rewrite of the previous edition. With this book, you'll learn how to use ActiveRecord to connect business objects and database tables. 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 are extensive chapters on testing, deployment, and scaling. As with the previous editions of the book, we start with an extended tutorial that builds parts of an online store. And the application has been rewritten to show the best of Rails 2. --from publisher description
In this updated edition of the Jolt Award-winning book, users are shown a new approach to Web development using Rails 2, making this the most up-to-date and authoritative Rails book out there.