OReilly rails cookbook jan 2007 ISBN 0596527314

1K 87 0
OReilly rails cookbook jan 2007 ISBN 0596527314

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Rails Cookbook By Rob Orsini Publisher: O'Reilly Pub Date: January 01, 2007 ISBN-10: 0-596-52731-4 ISBN-13: 978-0-596-52731-0 Pages: 600 Table of Contents | Index The Rails Cookbook is is packed with the solutions you need to be a proficient developer with Rails, the leading framework for building the new generation of Web 2.0 applications Recipes range from the basics, like installing Rails and setting up your development environment, to the latest techniques, such as developing RESTful web services With applications that are code light, feature-full and built to scale quickly, Rails has revolutionized web development The Rails Cookbook addresses scores of real-world challenges; each one includes a tested solution, plus a discussion of how and why it works, so that you can adapt the techniques to similar situations Topics include: Modeling data with the ActiveRecord library Setting up views with ActionView and RHTML templates Building your application's logic into ActionController Testing and debugging your Rails application Building responsive web applications using JavaScript and Ajax Ensuring that your application is security and performs well Deploying your application with Mongrel and Apache Using Capistrano to automate deployment Using the many Rails plugins Working with graphics Whether you're new to Rails or an experienced developer, you'll discover ways to test, bug and secure your applications, incorporate Ajax, use caching to improve performance, and put your application into production Want to get ahead of the Web 2.0 curve? This valuable cookbook will save you hundreds of hours when developing applications with Rails Rails Cookbook By Rob Orsini Publisher: O'Reilly Pub Date: January 01, 2007 ISBN-10: 0-596-52731-4 ISBN-13: 978-0-596-52731-0 Pages: 600 Table of Contents | Index Copyright Foreword Preface Chapter 1 Getting Started Section 1.0 Introduction Recipe 1.1 Joining the Rails Community Recipe 1.2 Finding Documentation Recipe 1.3 Installing MySQL Recipe 1.4 Installing PostgreSQL Recipe 1.5 Installing Rails Recipe 1.6 Fixing Ruby and Installing Rails on OS X 10.4 Tiger Recipe 1.7 Running Rails in OS X with Locomotive Recipe 1.8 Running Rails in Windows with Instant Rails Recipe 1.9 Updating Rails with RubyGems Recipe 1.10 Getting Your Rails Project into Subversion Chapter 2 Rails Development Section 2.0 Introduction Recipe 2.1 Creating a Rails Project Recipe 2.2 Jump-Starting Development with Scaffolding Recipe 2.3 Speeding Up Rails Development with Mongrel Recipe 2.4 Enhancing Windows Development with Cygwin Recipe 2.5 Understanding Pluralization Patterns in Rails Recipe 2.6 Developing Rails in OS X with TextMate Recipe 2.7 Cross-Platform Developing with RadRails Recipe 2.8 Installing and Running Edge Rails Recipe 2.9 Setting Up Passwordless Authentication with SSH Recipe 2.10 Generating RDoc for Your Rails Application Recipe 2.11 Creating Full-Featured CRUD Applications with Streamlined Chapter 3 Active Record Section 3.0 Introduction Recipe 3.1 Setting Up a Relational Database to Use with Rails Recipe 3.2 Programmatically Defining Database Schema Recipe 3.3 Developing Your Database with Migrations Recipe 3.4 Modeling a Database with Active Record Recipe 3.5 Inspecting Model Relationships from the Rails Console Recipe 3.6 Accessing Your Data via Active Record Recipe 3.7 Retrieving Records with find Recipe 3.8 Iterating Over an Active Record Result Set Recipe 3.9 Retrieving Data Efficiently with Eager Loading Recipe 3.10 Updating an Active Record Object Recipe 3.11 Enforcing Data Integrity with Active Record Validations Recipe 3.12 Executing Custom Queries with find_by_sql Recipe 3.13 Protecting Against Race Conditions with Transactions Recipe 3.14 Adding Sort Capabilities to a Model with acts_as_list Recipe 3.15 Performing a Task Whenever a Model Object Is Created Recipe 3.16 Modeling a Threaded Forum with acts_as_nested_set Recipe 3.17 Creating a Directory of Nested Topics with acts_as_tree Recipe 3.18 Avoiding Race Conditions with Optimistic Locking Recipe 3.19 Handling Tables with Legacy Naming Conventions Recipe 3.20 Automating Record Timestamping Recipe 3.21 Factoring Out Common Relationships with Polymorphic Associations Recipe 3.22 Mixing Join Models and Polymorphism for Flexible Data Modeling Chapter 4 Action Controller Section 4.0 Introduction Recipe 4.1 Accessing Form Data from a Controller Recipe 4.2 Changing an Application's Default Page Recipe 4.3 Clarifying Your Code with Named Routes Recipe 4.4 Configuring Customized Routing Behavior Recipe 4.5 Displaying Alert Messages with Flash Recipe 4.6 Extending the Life of a Flash Message Recipe 4.7 Following Actions with Redirects Recipe 4.8 Generating URLs Dynamically Recipe 4.9 Inspecting Requests with Filters Recipe 4.10 Logging with Filters Recipe 4.11 Rendering Actions Recipe 4.12 Restricting Access to Controller Methods Recipe 4.13 Sending Files or Data Streams to the Browser Recipe 4.14 Storing Session Information in a Database Recipe 4.15 Tracking Information with Sessions Recipe 4.16 Using Filters for Authentication Chapter 5 Action View Section 5.0 Introduction Recipe 5.1 Simplifying Templates with View Helpers Recipe 5.2 Displaying Large Datasets with Pagination Recipe 5.3 Creating a Sticky Select List Recipe 5.4 Editing Many-to-Many Relationships with Multiselect Lists Recipe 5.5 Factoring Out Common Display Code with Layouts Recipe 5.6 Defining a Default Application Layout Recipe 5.7 Generating XML with Builder Templates Recipe 5.8 Generating RSS Feeds from Active Record Data Recipe 5.9 Reusing Page Elements with Partials Recipe 5.10 Processing Dynamically Created Input Fields Recipe 5.11 Customizing the Behavior of Standard Helpers Recipe 5.12 Creating a Web Form with Form Helpers Recipe 5.13 Formatting Dates, Times, and Currencies Recipe 5.14 Personalizing User Profiles with Gravatars Recipe 5.15 Avoiding Harmful Code in Views with Liquid Templates Recipe 5.16 Globalizing Your Rails Application Chapter 6 RESTful Development Section 6.0 Introduction Recipe 6.1 Creating Nested Resources Recipe 6.2 Supporting Alternative Data Formats by MIME Type Recipe 6.3 Modeling Relationships RESTfully with Join Models Recipe 6.4 Moving Beyond Simple CRUD with RESTful Resources Recipe 6.5 Consuming Complex Nested REST Resources Recipe 6.6 Developing Your Rails Applications RESTfully Chapter 7 Rails Application Testing Section 7.0 Introduction Recipe 7.1 Centralizing the Creation of Objects Common to Test Cases Recipe 7.2 Creating Fixtures for Many-to-Many Associations Recipe 7.3 Importing Test Data with CSV Fixtures Recipe 7.4 Including Dynamic Data in Fixtures with ERb Recipe 7.5 Initializing a Test Database Recipe 7.6 Interactively Testing Controllers from the Rails Console Recipe 7.7 Interpreting the Output of Test::Unit Recipe 7.8 Loading Test Data with YAML Fixtures Recipe 7.9 Monitoring Test Coverage with rake stats Recipe 7.10 Running Tests with Rake Recipe 7.11 Speeding Up Tests with Transactional Fixtures Recipe 7.12 Testing Across Controllers with Integration Tests Recipe 7.13 Testing Controllers with Functional Tests Recipe 7.14 Examining the Contents of Cookie Recipe 7.15 Testing Custom and Named Routes Recipe 7.16 Testing HTTP Requests with Response-Related Assertions Recipe 7.17 Testing a Model with Unit Tests Recipe 7.18 Unit Testing Model Validations Recipe 7.19 Verifying DOM Structure with Tag-Related Assertions Recipe 7.20 Writing Custom Assertions Recipe 7.21 Testing File Upload Recipe 7.22 Modifying the Default Behavior of a Class for Testing by Using Mocks Recipe 7.23 Improving Feedback by Running Tests Continuously Recipe 7.24 Analyzing Code Coverage with Rcov Chapter 8 JavaScript and Ajax Section 8.0 Introduction Recipe 8.1 Adding DOM Elements to a Page Recipe 8.2 Creating a Custom Report with Drag and Drop Recipe 8.3 Dynamically Adding Items to a Select List Recipe 8.4 Monitoring the Content Length of a Textarea Recipe 8.5 Updating Page Elements with RJS Templates Recipe 8.6 Inserting JavaScript into Templates Recipe 8.7 Letting a User Reorder a List Recipe 8.8 Autocompleting a Text Field Recipe 8.9 Searching for and Highlighting Text Dynamically Recipe 8.10 Enhancing the User Interface with Visual Effects Recipe 8.11 Implementing a Live Search Recipe 8.12 Editing Fields in Place Recipe 8.13 Creating an Ajax Progress Indicator Chapter 9 Action Mailer Section 9.0 Introduction Recipe 9.1 Configuring Rails to Send Email Recipe 9.2 Creating a Custom Mailer Class with the Mailer Generator Recipe 9.3 Formatting Email Messages Using Templates Recipe 9.4 Attaching Files to Email Messages Recipe 9.5 Sending Email from a Rails Application Recipe 9.6 Receiving Email with Action Mailer Chapter 10 Debugging Rails Applications Section 10.0 Introduction Recipe 10.1 Exploring Rails from the Console Recipe 10.2 Fixing Bugs at the Source with Ruby -cw Recipe 10.3 Debugging Your Application in Real Time with the breakpointer Recipe 10.4 Logging with the Built-in Rails Logger Class Recipe 10.5 Writing Debugging Information to a File Recipe 10.6 Emailing Application Exceptions Recipe 10.7 Outputting Environment Information in Views Recipe 10.8 Displaying Object Contents with Exceptions Recipe 10.9 Filtering Development Logs in Real Time Recipe 10.10 Debugging HTTP Communication with Firefox Extensions Recipe 10.11 Debugging Your JavaScript in Real Time with the JavaScript Shell Recipe 10.12 Debugging Your Code Interactively with ruby-debug Chapter 11 Security Section 11.0 Introduction Recipe 11.1 Hardening Your Systems with Strong Passwords Recipe 11.2 Protecting Queries from SQL Injection Recipe 11.3 Guarding Against Cross-Site Scripting Attacks Recipe 11.4 Restricting Access to Public Methods or Actions Recipe 11.5 Securing Your Server by Closing Unnecessary Ports Chapter 12 Performance Section 12.0 Introduction Recipe 12.1 Measuring Web Server Performance with Httperf Recipe 12.2 Benchmarking Portions of Your Application Code Recipe 12.3 Improving Performance by Caching Static Pages Recipe 12.4 Expiring Cached Pages Recipe 12.5 Mixing Static and Dynamic Content with Fragment Caching Recipe 12.6 Filtering Cached Pages with Action Caching Recipe 12.7 Speeding Up Data Access Times with memcached Recipe 12.8 Increasing Performance by Caching Post-Processed Content Chapter 13 Hosting and Deployment Section 13.0 Introduction Recipe 13.1 Hosting Rails Using Apache 1.3 and mod_fastcgi Recipe 13.2 Managing Multiple Mongrel Processes with mongrel_cluster Recipe 13.3 Hosting Rails with Apache 2.2, mod_proxy_balancer, and Mongrel Recipe 13.4 Deploying Rails with Pound in Front of Mongrel, Lighttpd, and Apache Recipe 13.5 Customizing Pound's Logging with cronolog Recipe 13.6 Configuring Pound with SSL Support Recipe 13.7 Simple Load Balancing with Pen Recipe 13.8 Deploying Your Rails Project with Capistrano Recipe 13.9 Deploying Your Application to Multiple Environments with Capistrano Recipe 13.10 Deploying with Capistrano When You Can't Access Subversion Recipe 13.11 Deploying with Capistrano and mongrel_cluster Recipe 13.12 Disabling Your Web Site During Maintenance Recipe 13.13 Writing Custom Capistrano Tasks Recipe 13.14 Cleaning Up Residual Session Records Chapter 14 Extending Rails with Plug-ins Section 14.0 Introduction Recipe 14.1 Finding Third-Party Plug-ins Recipe 14.2 Installing Plug-ins Recipe 14.3 Manipulating Record Versions with acts_as_versioned Recipe 14.4 Building Authentication with acts_as_authenticated Recipe 14.5 Simplifying Folksonomy with the acts_as_taggable Recipe 14.6 Extending Active Record with acts_as Recipe 14.7 Adding View Helpers to Rails as Plug-ins Recipe 14.8 Uploading Files with file_column Recipe 14.9 Uploading Files with acts_as_attachment Recipe 14.10 Disabling Records Instead of Deleting Them with acts_as_paranoid Recipe 14.11 Adding More Elaborate Authentication Using the Login Engine Chapter 15 Graphics Section 15.0 Introduction Recipe 15.1 Installing RMagick for Image Processing Recipe 15.2 Uploading Images to a Database Recipe 15.3 Serving Images Directly from a Database Recipe 15.4 Creating Resized Thumbnails with RMagick Recipe 15.5 Generating PDF Documents Recipe 15.6 Visually Displaying Data with Gruff Recipe 15.7 Creating Small, Informative Graphs with Sparklines Appendix A Migrating to Rails 1.2 Action Controller Active Record Action View Colophon Index Copyright Copyright © 2007, O'Reilly Media All rights reserved Printed in in the United States of America Published by O'Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472 O'Reilly books may be purchased for educational, business, or sales promotional use Online editions are also available for most titles (http://safari.oreilly.com) For more information, contact our corporate/institutional sales department: (800) 998-9938 or corporate@oreilly.com Editor: Mike Loukides Production Editor: Laurel R.T Ruma Editor: Mary Anne Weeks Mayo Nutshell Handbook, the Nutshell Handbook logo, and the O'Reilly logo are registered trademarks of O'Reilly Media, Inc Rails Cookbook, the image of a Cape hunting dog, and related trade dress are trademarks of O'Reilly Media, Inc Many of the designations uses by manufacturers and sellers to distinguish their products are claimed as trademarks Where those designations appear in this book, and O'Reilly Media, Inc was aware of a trademark claim, the designations have been printed in caps or initial caps While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein rcov RDoc (Ruby documentation) generating :readonly parameter (find) Really Simple Syndication (RSS) feeds record timestamping, automating Red Hat :redirect status code (assert_response) redirect_to redirect_to controller method redirect_to_path controller method deprecated, using redirect_to redirect_to_url controller method redirects, following actions with reflected XSS attacks relational databases Active Record, modeling with setting up remove command (plugin) remove_from_list method render helper (Capistrano) render method deprecated, usein render :file => #{options} repositories (Subversion), creating Representational State Transfer [See REST] request methods request variable 2nd request.env[ ] residual session records response controller instance variable response-related assertions REST (Representational State Transfer) complex nested resources and developing applications with join models, modeling relationships moving beyond CRUD with nested resources and restart task (mongrel_cluster) restart_mongrel_cluster task (mongrel_cluster) result sets revision control rhtml extension rjs extension RJS templates rm command RMagick 2nd 3rd installing resizing thumbnails with roles input fields, processing dynamically many-to-many relationships root method routing behavior, configuring RSS (Really Simple Syndication) feeds rsync program Ruby Core library Ruby documentation (RDoc) generating Ruby FPDF Ruby Standard Library ruby-debug ruby-dev package RubyForge RubyGems 2nd 3rd installing Ruby and MySQL, installing and projects, creating updating rails with #rubyonrails IRC channel rubyonrails-core mailing list rubyonrails-security mailing list rubyonrails-spinoffs mailing list rubyonrails-talks mailing list RUGs (Ruby User Groups) run helper (Capistrano) runtime environments for development RuntimeError exception rxml extension Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] %S date format string option save! method scaffold generator CRUD applications and scaffold method scaffolding, development with SCGI module schema (database), defining scp program script directory search_results action @sections variable Secure Socket Layer [See SSL] security cross-site scripting attacks, guarding against hardening systems with strong passwords restricting access public methods/actions servers, securing by closing unnecessary ports SQL injection, protecting queries from select for update select lists creating multi :select parameter (find) self_and_siblings method server-status utility session hash storing sessions in databases sessions residual records, cleaning up storing in databases tracking information with setup method, testing code sftp program Shaw, Zed :sibling option (assert_tag) siblings method Simple Mail Transfer Protocol (SMTP) simply_restful plug-in :singular configuration option singularization of database class names smooth graphs SMTP (Simple Mail Transfer Protocol) sort capabilities, using acts_as_list method source command (plugin) sources command (plugin) Sparklines 2nd sparklines_generator gems specification command (gem) spinner task (mongrel_cluster) splats, creating bold text in RDocs SQL injection 2nd protecting queries from SQL, using REST and square brackets ([ ]), using params hash with SSH Capistrano and passwordless authentication, setting up SSL (Secure Socket Layer), configuring Pound standard helpers start_mongrel_cluster task (mongrel_cluster) stateless of the Web static pages, caching stats rake task status code numbers stop_mongrel_cluster task (mongrel_cluster) stored XSS attacks Streamlined strftime method String class strip! method subclipse Eclipse plug-in subtemplates creating Subversion Edge Rails and globalizing applications :success status code (assert_response) sudo helper (Capistrano) svn propedit command svn:externals property (svn propedit command) SwitchTower syntax errors Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] tables (database) pluralization of tables, handling legacy naming conventions :tag option (assert_tag) tag-related assertions tag_list method tag_with method tail -f command tasks, executing commands across servers teardown method, testing code templates email, formatting with factoring out common display code with layouts Liquid templates, avoiding harmful code and RSS feeds, generating subtemplates and view helpers, simplifying with XML, outputting with Builder test directory test runtime environments Test::Unit method 2nd 3rd DOM structure, verifying interpreting output of testing text! method Textile TextMate 2nd -cw option and third-party plug-ins threaded forums, modeling with acts_as_nested_set method thumbnails, resizing Tiger Mac OS X 10.4, installing Rails/fixing Ruby Time object times timestamps, automating title parameter (benchmark method) TMail library transaction (web) transaction helper (Capistrano) transaction method transactional fixtures Tufte, Edward Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] %U date format string option underscores (_), italicizing text in RDocs Unicode unit tests model validations and unsource command (plugin) update_code task update_perms method updating/upgrading url_for method 2nd url_for_gravatar method URLs generating dynamically user groups (Ruby) user profiles, personalizing :user variable User.transaction( ) method :user_name parameter (ActionMailer::Base.server_settings) users input fields, processing dynamically many-to-many relationships :utc option (environment.rb) UTF-8 encoding Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] %v date format string option validations module vendor directory verbs (REST) view helpers adding as plug-ins simplifying templates views Vim VirtualHost directives Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] %W date format string option %w date format string option web forms, accessing data from controllers web server performance WEBrick 2nd 3rd Instant Rails and Mongrel, as an alternative to Windows Capistrano, running on console (Rail) Cygwin, enhancing development with Mongrel and MySQL and PostgreSQL RMagick, installing running Rails with with-experimental-only-ssl option with-ssl option (SSL) Word class Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] %x date format string option X-Chat X11 SDK XCode Tools XHTML (eXtensible Hypertext Markup Language) assert_tag and XML (eXtensible Markup Language) builder templates, outputting MIME types and RSS feed, generating XMLHttpRequest XSS (cross-site scripting) guarding against Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] y (yaml) [See yaml (y)] %Y date format string option yaml (y) 2nd 3rd test fixtures, creating YAML fixtures 2nd ERb, including dynamic data in loading test data with yield method Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] %Z date format string option ZeroDivisionError exception Zygmuntowicz, Ezra ...valuable cookbook will save you hundreds of hours when developing applications with Rails Rails Cookbook By Rob Orsini Publisher: O'Reilly Pub Date: January 01, 2007 ISBN- 10: 0-596-52731-4 ISBN- 13: 978-0-596-52731-0... Running Rails in OS X with Locomotive Recipe 1.8 Running Rails in Windows with Instant Rails Recipe 1.9 Updating Rails with RubyGems Recipe 1.10 Getting Your Rails Project into Subversion Chapter 2 Rails Development... Tiger Recipe 1.7 Running Rails in OS X with Locomotive Recipe 1.8 Running Rails in Windows with Instant Rails Recipe 1.9 Updating Rails with RubyGems Recipe 1.10 Getting Your Rails Project into Subversion

Ngày đăng: 26/03/2019, 17:06

Từ khóa liên quan

Mục lục

  • Rails Cookbook

  • Table of Contents

  • Copyright

  • Foreword

    • Preface

    • Chapter 1. Getting Started

      • Section 1.0. Introduction

      • Recipe 1.1. Joining the Rails Community

      • Recipe 1.2. Finding Documentation

      • Recipe 1.3. Installing MySQL

      • Recipe 1.4. Installing PostgreSQL

      • Recipe 1.5. Installing Rails

      • Recipe 1.6. Fixing Ruby and Installing Rails on OS X 10.4 Tiger

      • Recipe 1.7. Running Rails in OS X with Locomotive

      • Recipe 1.8. Running Rails in Windows with Instant Rails

      • Recipe 1.9. Updating Rails with RubyGems

      • Recipe 1.10. Getting Your Rails Project into Subversion

      • Chapter 2. Rails Development

        • Section 2.0. Introduction

        • Recipe 2.1. Creating a Rails Project

        • Recipe 2.2. Jump-Starting Development with Scaffolding

        • Recipe 2.3. Speeding Up Rails Development with Mongrel

        • Recipe 2.4. Enhancing Windows Development with Cygwin

Tài liệu cùng người dùng

Tài liệu liên quan