Rails Cookbook

  • ISBN13:


  • ISBN10:


  • Format: Paperback
  • Copyright: 2007-01-01
  • Publisher: Oreilly & Associates Inc
  • Purchase Benefits
  • Free Shipping On Orders Over $35!
    Your order must be $35 or more to qualify for free economy shipping. Bulk sales, PO's, Marketplace items, eBooks and apparel do not qualify for this offer.
  • Get Rewarded for Ordering Your Textbooks! Enroll Now
List Price: $39.99 Save up to $6.00
  • Buy New


Supplemental Materials

What is included with this book?

  • The New copy of this book will include any supplemental materials advertised. Please check the title of the book to determine if it should include any access cards, study guides, lab manuals, CDs, etc.
  • The eBook copy of this book is not guaranteed to include any supplemental materials. Typically, only the book itself is included. This is true even if the title states it includes any access cards, study guides, lab manuals, CDs, etc.


Rails is one of the leading frameworks for developing the new generation of Web 2.0 applications using the increasingly popular Ruby scripting language. This new Cookbook title is for all web developers, regardless of experience, who want learn about the fastest-growing web application framework on the market. "Rails Cookbook" is not an introductory tutorial, but a problem-solving book that provides coding solutions that appeal to a wide range of audiences, from the inexperienced to the expert. For every problem addressed in the book, there's a worked-out solution or "recipe"-- a short, focused piece of code that web developers can insert directly into their applications. Topics covered in the book include developing scalable web applications, test-driven development, working with active record, and deploying Rails applications. A discussion on each solution is included, so developers can learn to adapt the problem-solving techniques to similar situations. This ultimate Rails code sourcebook will save readers hundreds of hours.

Author Biography

Rob Orsini is the author of the Rails Cookbook (O'Reilly). He's also the founder and CEO of Tuple Shop, Inc., a web software consulting company specializing in Rails and Python development. Previously, Rob was webmaster at Industrial Light & Magic (a Lucasfilm company), and software engineer at O'Reilly Media. Rob has been programming the web since the late nineties, and enjoys the leading edge of development with dynamic languages such as Ruby and Python. Additionally, Rob is a jazz musician, a builder, and a loving husband and father.

Table of Contents

Forewordp. xi
Prefacep. xiii
Getting Startedp. 1
Joining the Rails Communityp. 2
Finding Documentationp. 4
Installing MySQLp. 5
Installing PostgreSQLp. 8
Installing Railsp. 10
Fixing Ruby and Installing Rails on OS X 10.4 Tigerp. 12
Running Rails in OS X with Locomotivep. 14
Running Rails in Windows with Instant Railsp. 16
Updating Rails with RubyGemsp. 18
Getting Your Rails Project into Subversionp. 19
Rails Developmentp. 23
Creating a Rails Projectp. 23
Jump-Starting Development with Scaffoldingp. 26
Speeding Up Rails Development with Mongrelp. 28
Enhancing Windows Development with Cygwinp. 31
Understanding Pluralization Patterns in Railsp. 32
Developing Rails in OS X with TextMatep. 36
Cross-Platform Developing with RadRailsp. 37
Installing and Running Edge Railsp. 38
Setting Up Passwordless Authentication with SSHp. 41
Generating RDoc for Your Rails Applicationp. 42
Creating Full-Featured CRUD Applications with Streamlinedp. 45
Active Recordp. 49
Setting Up a Relational Database to Use with Railsp. 50
Programmatically Defining Database Schemap. 54
Developing Your Database with Migrationsp. 56
Modeling a Database with Active Recordp. 60
Inspecting Model Relationships from the Rails Consolep. 63
Accessing Your Data via Active Recordp. 66
Retrieving Records with findp. 68
Iterating Over an Active Record Result Setp. 71
Retrieving Data Efficiently with Eager Loadingp. 74
Updating an Active Record Objectp. 77
Enforcing Data Integrity with Active Record Validationsp. 81
Executing Custom Queries with find_by_sqlp. 84
Protecting Against Race Conditions with Transactionsp. 88
Adding Sort Capabilities to a Model with acts_as_listp. 92
Performing a Task Whenever a Model Object Is Createdp. 97
Modeling a Threaded Forum with acts_as_nested_setp. 100
Creating a Directory of Nested Topics with acts_as_treep. 104
Avoiding Race Conditions with Optimistic Lockingp. 107
Handling Tables with Legacy Naming Conventionsp. 109
Automating Record Timestampingp. 111
Factoring Out Common Relationships with Polymorphic Associationsp. 112
Mixing Join Models and Polymorphism for Flexible Data Modelingp. 115
Action Controllerp. 121
Accessing Form Data from a Controllerp. 122
Changing an Application's Default Pagep. 125
Clarifying Your Code with Named Routesp. 126
Configuring Customized Routing Behaviorp. 127
Displaying Alert Messages with Flashp. 129
Extending the Life of a Flash Messagep. 131
Following Actions with Redirectsp. 133
Generating URLs Dynamicallyp. 134
Inspecting Requests with Filtersp. 135
Logging with Filtersp. 137
Rendering Actionsp. 140
Restricting Access to Controller Methodsp. 141
Sending Files or Data Streams to the Browserp. 142
Storing Session Information in a Databasep. 144
Tracking Information with Sessionsp. 146
Using Filters for Authenticationp. 149
Action Viewp. 155
Simplifying Templates with View Helpersp. 156
Displaying Large Datasets with Paginationp. 158
Creating a Sticky Select Listp. 161
Editing Many-to-Many Relationships with Multiselect Listsp. 163
Factoring Out Common Display Code with Layoutsp. 166
Defining a Default Application Layoutp. 169
Generating XML with Builder Templatesp. 170
Generating RSS Feeds from Active Record Datap. 172
Reusing Page Elements with Partialsp. 174
Processing Dynamically Created Input Fieldsp. 177
Customizing the Behavior of Standard Helpersp. 181
Creating a Web Form with Form Helpersp. 183
Formatting Dates, Times, and Currenciesp. 187
Personalizing User Profiles with Gravatarsp. 190
Avoiding Harmful Code in Views with Liquid Templatesp. 191
Globalizing Your Rails Applicationp. 195
Restful Developmentp. 201
Creating Nested Resourcesp. 204
Supporting Alternative Data Formats by MIME Typep. 208
Modeling Relationships Restfully with Join Modelsp. 210
Moving Beyond Simple CRUD with Restful Resourcesp. 213
Consuming Complex Nested Rest Resourcesp. 217
Developing Your Rails Applications Restfullyp. 220
Rails Application Testingp. 225
Centralizing the Creation of Objects Common to Test Casesp. 226
Creating Fixtures for Many-to-Many Associationsp. 227
Importing Test Data with CSV Fixturesp. 229
Including Dynamic Data in Fixtures with ERbp. 232
Initializing a Test Databasep. 233
Interactively Testing Controllers from the Rails Consolep. 235
Interpreting the Output of Test::Unitp. 237
Loading Test Data with YAML Fixturesp. 238
Monitoring Test Coverage with rake statsp. 240
Running Tests with Rakep. 241
Speeding Up Tests with Transactional Fixturesp. 242
Testing Across Controllers with Integration Testsp. 244
Testing Controllers with Functional Testsp. 247
Examining the Contents of Cookiep. 250
Testing Custom and Named Routesp. 253
Testing HTTP Requests with Response-Related Assertionsp. 255
Testing a Model with Unit Testsp. 256
Unit Testing Model Validationsp. 259
Verifying DOM Structure with Tag-Related Assertionsp. 261
Writing Custom Assertionsp. 264
Testing File Uploadp. 265
Modifying the Default Behavior of a Class for Testing by Using Mocksp. 269
Improving Feedback by Running Tests Continuouslyp. 271
Analyzing Code Coverage with Rcovp. 272
JavaScript and Ajaxp. 277
Adding DOM Elements to a Pagep. 278
Creating a Custom Report with Drag and Dropp. 281
Dynamically Adding Items to a Select Listp. 286
Monitoring the Content Length of a Textareap. 288
Updating Page Elements with RJS Templatesp. 292
Inserting JavaScript into Templatesp. 295
Letting a User Reorder a Listp. 298
Autocompleting a Text Fieldp. 302
Searching for and Highlighting Text Dynamicallyp. 304
Enhancing the User Interface with Visual Effectsp. 308
Implementing a Live Searchp. 311
Editing Fields in Placep. 315
Creatingan Ajax Progress Indicatorp. 317
Action Mailerp. 321
Configuring Rails to Send Emailp. 322
Creating a Custom Mailer Class with the Mailer Generatorp. 323
Formatting Email Messages Using Templatesp. 325
Attaching Files to Email Messagesp. 326
Sending Email from a Rails Applicationp. 327
Receiving Email with Action Mailerp. 328
Debugging Rails Applicationsp. 333
Exploring Rails from the Consolep. 334
Fixing Bugs at the Source with Ruby -cwp. 336
Debugging Your Application in Real Time with the breakpointerp. 338
Logging with the Built-in Rails Logger Classp. 342
Writing Debugging Information to a Filep. 344
Emailing Application Exceptionsp. 346
Outputting Environment Information in Viewsp. 350
Displaying Object Contents with Exceptionsp. 352
Filtering Development Logs in Real Timep. 353
Debugging HTTP Communication with Firefox Extensionsp. 355
Debugging Your JavaScript in Real Time with the JavaScript Shellp. 356
Debugging Your Code Interactively with ruby-debugp. 360
Securityp. 365
Hardening Your Systems with Strong Passwordsp. 365
Protecting Queries from SQL Injectionp. 368
Guarding Against Cross-Site Scripting Attacksp. 369
Restricting Access to Public Methods or Actionsp. 371
Securing Your Server by Closing Unnecessary Portsp. 373
Performancep. 377
Measuring Web Server Performance with Httperfp. 378
Benchmarking Portions of Your Application Codep. 381
Improving Performance by Caching Static Pagesp. 382
Expiring Cached Pagesp. 385
Mixing Static and Dynamic Content with Fragment Cachingp. 388
Filtering Cached Pages with Action Cachingp. 391
Speeding Up Data Access Times with memcachedp. 392
Increasing Performance by Caching Post-Processed Contentp. 395
Hosting and Deploymentp. 399
Hosting Rails Using Apache 1.3 and mod_fastcgip. 400
Managing Multiple Mongrel Processes with mongrel_clusterp. 402
Hosting Rails with Apache 2.2, mod_proxy_balancer, and Mongrelp. 405
Deploying Rails with Pound in Front of Mongrel, Lighttpd, and Apachep. 409
Customizing Pound's Logging with cronologp. 413
Configuring Pound with SSL Supportp. 416
Simple Load Balancing with Penp. 418
Deploying Your Rails Project with Capistranop. 419
Deploying Your Application to Multiple Environments with Capistranop. 423
Deploying with Capistrano When You Can't Access Subversionp. 425
Deploying with Capistrano and mongrel_clusterp. 427
Disabling Your Web Site During Maintenancep. 429
Writing Custom Capistrano Tasksp. 432
Cleaning Up Residual Session Recordsp. 436
Extending Rails with Plug-insp. 439
Finding Third-Party Plug-insp. 440
Installing Plug-insp. 441
Manipulating Record Versions with acts_as_versionedp. 443
Building Authentication with acts_as_authenticatedp. 446
Simplifying Folksonomy with the acts_as_taggablep. 450
Extending Active Record with acts_asp. 455
Adding View Helpers to Rails as Plug-insp. 460
Uploading Files with file_columnp. 462
Uploading Files with acts_as_attachmentp. 465
Disabling Records Instead of Deleting Them with acts_as_paranoidp. 469
Adding More Elaborate Authentication Using the Login Enginep. 471
Graphicsp. 475
Installing RMagick for Image Processingp. 475
Uploading Images to a Databasep. 480
Serving Images Directly from a Databasep. 484
Creating Resized Thumbnails with RMagickp. 485
Generating PDF Documentsp. 488
Visually Displaying Data with Gruffp. 490
Creating Small, Informative Graphs with Sparklinesp. 493
Migrating to Rails 1.2p. 497
Indexp. 501
Table of Contents provided by Ingram. All Rights Reserved.

Rewards Program

Write a Review