Rails Cookbook(影印版)
Rails Cookbook(影印版)
Rob Orsini
出版时间:2007年07月
页数:514
Rails是业界领先的新一代Web 2.0应用程序开发框架,在这本《Rails Cookbook》里充满了为了让你成为Rails开发专家而准备的各种解决方案。讨论范围从基本概念,如安装Rails及设置开发环境,到最新的各种技巧,如开发符合REST协议规范的Web服务等。
Rails可提供更轻量级的代码、更丰富的功能和更快捷的量身定制过程,由此带来了一场Web开发革命。《Rails Cookbook》应对来自真实世界的各种挑战,每个问题的解答部分均包含了经测试验证的解决方案,加上关于怎样解决和为什么如此解决的讨论。因此你不仅可以知其然,还能知其所以然,以便将相关技巧直接运用于类似的场景。议题涵盖:
*以Active Record库进行数据建模
*以Action View和RHTML模板创建视图
*在Action Controller中构建应用程序逻辑
*测试并调试Rails应用程序
*以JavaScript和Ajax构建交互式Web应用程序
*确保应用程序的安全性和可用性
*以Mongrel和Apache部署应用程序
*使用Capistrano实现自动化部署
*使用大量Rails插件
无论是Rails新手还是经验丰富的资深开发者,你都将从本书中发现一系列有效方法,涉及测试、调试和保护你的应用程序、引入Ajax、运用缓存改善性能以及将应用程序放入生产环境等方方面面。想抢占Web 2.0潮流的先机吗?这本极具价值的书会让你在开发Rails应用程序的过程中节省数百小时的宝贵时间。
“《Rails Cookbook》满足了我的所有期望……简洁、贴切、新颖,对于初学者和
专家都有用。更棒的是,它源自Rails社区里我最喜欢的那帮家伙,是一份真正的团队合作成果。”
----Geoffrey Grosenbach, Ruby on Rails Podcast的主持人
“一看完第3章我就知道该向初学Rails的人们推荐这本书了。它涵盖了Rails开发入门所需的基本知识。《Rails Cookbook》也包括了很多如测试和REST风格开发等高级议题,给那些有经验的Ruby开发者一个改善现有设计技巧的新起点。”
----Kevin Clark, http://glu.ttono.us
  1. Foreword
  2. Preface
  3. 1. Getting Started
  4. 1.1 Joining the Rails Community
  5. 1.2 Finding Documentation
  6. 1.3 Installing MySQL
  7. 1.4 Installing PostgreSQL
  8. 1.5 Installing Rails
  9. 1.6 Fixing Ruby and Installing Rails on OS X 10.4 Tiger
  10. 1.7 Running Rails in OS X with Locomotive
  11. 1.8 Running Rails in Windows with Instant Rails
  12. 1.9 Updating Rails with RubyGems
  13. 1.10 Getting Your Rails Project into Subversion
  14. 2. Rails Development
  15. 2.1 Creating a Rails Project
  16. 2.2 Jump-Starting Development with Scaffolding
  17. 2.3 Speeding Up Rails Development with Mongrel
  18. 2.4 Enhancing Windows Development with Cygwin
  19. 2.5 Understanding Pluralization Patterns in Rails
  20. 2.6 Developing Rails in OS X with TextMate
  21. 2.7 Cross-Platform Developing with RadRails
  22. 2.8 Installing and Running Edge Rails
  23. 2.9 Setting Up Passwordless Authentication with SSH
  24. 2.10 Generating RDoc for Your Rails Application
  25. 2.11 Creating Full-Featured CRUD Applications with Streamlined
  26. 3. Active Record
  27. 3.1 Setting Up a Relational Database to Use with Rails
  28. 3.2 Programmatically Defining Database Schema
  29. 3.3 Developing Your Database with Migrations
  30. 3.4 Modeling a Database with Active Record
  31. 3.5 Inspecting Model Relationships from the Rails Console
  32. 3.6 Accessing Your Data via Active Record
  33. 3.7 Retrieving Records with find
  34. 3.8 Iterating Over an Active Record Result Set
  35. 3.9 Retrieving Data Efficiently with Eager Loading
  36. 3.10 Updating an Active Record Object
  37. 3.11 Enforcing Data Integrity with Active Record Validations
  38. 3.12 Executing Custom Queries with find_by_sql
  39. 3.13 Protecting Against Race Conditions with Transactions
  40. 3.14 Adding Sort Capabilities to a Model with acts_as_list
  41. 3.15 Performing a Task Whenever a Model Object Is Created
  42. 3.16 Modeling a Threaded Forum with acts_as_nested_set
  43. 3.17 Creating a Directory of Nested Topics with acts_as_tree
  44. 3.18 Avoiding Race Conditions with Optimistic Locking
  45. 3.19 Handling Tables with Legacy Naming Conventions
  46. 3.20 Automating Record Timestamping
  47. 3.21 Factoring Out Common Relationships with Polymorphic
  48. Associations
  49. 3.22 Mixing Join Models and Polymorphism for Flexible Data
  50. Modeling
  51. 4. Action Controller
  52. 4.1 Accessing Form Data from a Controller
  53. 4.2 Changing an Application’s Default Page
  54. 4.3 Clarifying Your Code with Named Routes
  55. 4.4 Configuring Customized Routing Behavior
  56. 4.5 Displaying Alert Messages with Flash
  57. 4.6 Extending the Life of a Flash Message
  58. 4.7 Following Actions with Redirects
  59. 4.8 Generating URLs Dynamically
  60. 4.9 Inspecting Requests with Filters
  61. 4.10 Logging with Filters
  62. 4.11 Rendering Actions
  63. 4.12 Restricting Access to Controller Methods
  64. 4.13 Sending Files or Data Streams to the Browser
  65. 4.14 Storing Session Information in a Database
  66. 4.15 Tracking Information with Sessions
  67. 4.16 Using Filters for Authentication
  68. 5. Action View
  69. 5.1 Simplifying Templates with View Helpers
  70. 5.2 Displaying Large Datasets with Pagination
  71. 5.3 Creating a Sticky Select List
  72. 5.4 Editing Many-to-Many Relationships with Multiselect Lists
  73. 5.5 Factoring Out Common Display Code with Layouts
  74. 5.6 Defining a Default Application Layout
  75. 5.7 Generating XML with Builder Templates
  76. 5.8 Generating RSS Feeds from Active Record Data
  77. 5.9 Reusing Page Elements with Partials
  78. 5.10 Processing Dynamically Created Input Fields
  79. 5.11 Customizing the Behavior of Standard Helpers
  80. 5.12 Creating a Web Form with Form Helpers
  81. 5.13 Formatting Dates, Times, and Currencies
  82. 5.14 Personalizing User Profiles with Gravatars
  83. 5.15 Avoiding Harmful Code in Views with Liquid Templates
  84. 5.16 Globalizing Your Rails Application
  85. 6. RESTful Development
  86. 6.1 Creating Nested Resources
  87. 6.2 Supporting Alternative Data Formats by MIME Type
  88. 6.3 Modeling Relationships RESTfully with Join Models
  89. 6.4 Moving Beyond Simple CRUD with RESTful Resources
  90. 6.5 Consuming Complex Nested REST Resources
  91. 6.6 Developing Your Rails Applications RESTfully
  92. 7. Rails Application Testing
  93. 7.1 Centralizing the Creation of Objects Common to Test Cases
  94. 7.2 Creating Fixtures for Many-to-Many Associations
  95. 7.3 Importing Test Data with CSV Fixtures
  96. 7.4 Including Dynamic Data in Fixtures with ERb
  97. 7.5 Initializing a Test Database
  98. 7.6 Interactively Testing Controllers from the Rails Console
  99. 7.7 Interpreting the Output of Test::Unit
  100. 7.8 Loading Test Data with YAML Fixtures
  101. 7.9 Monitoring Test Coverage with rake stats
  102. 7.10 Running Tests with Rake
  103. 7.11 Speeding Up Tests with Transactional Fixtures
  104. 7.12 Testing Across Controllers with Integration Tests
  105. 7.13 Testing Controllers with Functional Tests
  106. 7.14 Examining the Contents of Cookie
  107. 7.15 Testing Custom and Named Routes
  108. 7.16 Testing HTTP Requests with Response-Related Assertions
  109. 7.17 Testing a Model with Unit Tests
  110. 7.18 Unit Testing Model Validations
  111. 7.19 Verifying DOM Structure with Tag-Related Assertions
  112. 7.20 Writing Custom Assertions
  113. 7.21 Testing File Upload
  114. 7.22 Modifying the Default Behavior of a Class for Testing by Using
  115. Mocks
  116. 7.23 Improving Feedback by Running Tests Continuously
  117. 7.24 Analyzing Code Coverage with Rcov
  118. 8. JavaScript and Ajax
  119. 8.1 Adding DOM Elements to a Page
  120. 8.2 Creating a Custom Report with Drag and Drop
  121. 8.3 Dynamically Adding Items to a Select List
  122. 8.4 Monitoring the Content Length of a Textarea
  123. 8.5 Updating Page Elements with RJS Templates
  124. 8.6 Inserting JavaScript into Templates
  125. 8.7 Letting a User Reorder a List
  126. 8.8 Autocompleting a Text Field
  127. 8.9 Searching for and Highlighting Text Dynamically
  128. 8.10 Enhancing the User Interface with Visual Effects
  129. 8.11 Implementing a Live Search
  130. 8.12 Editing Fields in Place
  131. 8.13 Creating an Ajax Progress Indicator
  132. 9. Action Mailer
  133. 9.1 Configuring Rails to Send Email
  134. 9.2 Creating a Custom Mailer Class with the Mailer Generator
  135. 9.3 Formatting Email Messages Using Templates
  136. 9.4 Attaching Files to Email Messages
  137. 9.5 Sending Email from a Rails Application
  138. 9.6 Receiving Email with Action Mailer
  139. 10. Debugging Rails Applications
  140. 10.1 Exploring Rails from the Console
  141. 10.2 Fixing Bugs at the Source with Ruby -cw
  142. 10.3 Debugging Your Application in Real Time with the
  143. breakpointer
  144. 10.4 Logging with the Built-in Rails Logger Class
  145. 10.5 Writing Debugging Information to a File
  146. 10.6 Emailing Application Exceptions
  147. 10.7 Outputting Environment Information in Views
  148. 10.8 Displaying Object Contents with Exceptions
  149. 10.9 Filtering Development Logs in Real Time
  150. 10.10 Debugging HTTP Communication with Firefox Extensions
  151. 10.11 Debugging Your JavaScript in Real Time with the JavaScript
  152. Shell
  153. 10.12 Debugging Your Code Interactively with ruby-debug
  154. 11. Security
  155. 11.1 Hardening Your Systems with Strong Passwords
  156. 11.2 Protecting Queries from SQL Injection
  157. 11.3 Guarding Against Cross-Site Scripting Attacks
  158. 11.4 Restricting Access to Public Methods or Actions
  159. 11.5 Securing Your Server by Closing Unnecessary Ports
  160. 12. Performance
  161. 12.1 Measuring Web Server Performance with Httperf
  162. 12.2 Benchmarking Portions of Your Application Code
  163. 12.3 Improving Performance by Caching Static Pages
  164. 12.4 Expiring Cached Pages
  165. 12.5 Mixing Static and Dynamic Content with Fragment Caching
  166. 12.6 Filtering Cached Pages with Action Caching
  167. 12.7 Speeding Up Data Access Times with memcached
  168. 12.8 Increasing Performance by Caching Post-Processed Content
  169. 13. Hosting and Deployment
  170. 13.1 Hosting Rails Using Apache 1.3 and mod_fastcgi
  171. 13.2 Managing Multiple Mongrel Processes with mongrel_cluster
  172. 13.3 Hosting Rails with Apache 2.2, mod_proxy_balancer, and
  173. Mongrel
  174. 13.4 Deploying Rails with Pound in Front of Mongrel, Lighttpd,
  175. and Apache
  176. 13.5 Customizing Pound’s Logging with cronolog
  177. 13.6 Configuring Pound with SSL Support
  178. 13.7 Simple Load Balancing with Pen
  179. 13.8 Deploying Your Rails Project with Capistrano
  180. 13.9 Deploying Your Application to Multiple Environments with
  181. Capistrano
  182. 13.10 Deploying with Capistrano When You Can’t Access Subversion
  183. 13.11 Deploying with Capistrano and mongrel_cluster
  184. 13.12 Disabling Your Web Site During Maintenance
  185. 13.13 Writing Custom Capistrano Tasks
  186. 13.14 Cleaning Up Residual Session Records
  187. 14. Extending Rails with Plug-ins
  188. 14.1 Finding Third-Party Plug-ins
  189. 14.2 Installing Plug-ins
  190. 14.3 Manipulating Record Versions with acts_as_versioned
  191. 14.4 Building Authentication with acts_as_authenticated
  192. 14.5 Simplifying Folksonomy with the acts_as_taggable
  193. 14.6 Extending Active Record with acts_as
  194. 14.7 Adding View Helpers to Rails as Plug-ins
  195. 14.8 Uploading Files with file_column
  196. 14.9 Uploading Files with acts_as_attachment
  197. 14.10 Disabling Records Instead of Deleting Them with
  198. acts_as_paranoid
  199. 14.11 Adding More Elaborate Authentication Using the Login Engine
  200. 15. Graphics
  201. 15.1 Installing RMagick for Image Processing
  202. 15.2 Uploading Images to a Database
  203. 15.3 Serving Images Directly from a Database
  204. 15.4 Creating Resized Thumbnails with RMagick
  205. 15.5 Generating PDF Documents
  206. 15.6 Visually Displaying Data with Gruff
  207. 15.7 Creating Small, Informative Graphs with Sparklines
  208. Appendix: Migrating to Rails 1.2
  209. Index
书名:Rails Cookbook(影印版)
作者:Rob Orsini
国内出版社:东南大学出版社
出版时间:2007年07月
页数:514
书号:978-7-5641-0780-2
原版书出版商:O'Reilly Media
Rob Orsini
 
Rob Orsini是一位开源开发者,他现居住在加利福尼亚北部,就职于O’Reilly Media公司软件产品组。在此之前,他担任Industrial Light&Magic网站的管理员,从事一些与工业相关的特定的应用程序的开发。Rob从1998年开始从事Web开发工作,不久后发现了Rails并希望自己今后一直能在这方面工作下去。他同时也是一位爵士音乐家,而且还是一位非常慈爱的父亲。
Rob Orsini is an open source developer living in northern California. He currently works for O'Reilly Media in the production software group. Previously, Rob was the webmaster at Industrial Light & Magic, where he developed applications in support of the special effects industry. Rob has been programming the Web since 1998, and upon discovering Rails, hopes to continue for many more years to come. Rob is also a jazz musician and a loving father.
 
 
The animal on the cover of Rails Cookbook is a Cape hunting dog (Lycaon pictus), also known as the painted wolf or African wild dog. Cape hunting dogs are only found in African plains and semi-desert areas. Both male and female Cape hunting dogs weigh about 45 to 60 pounds (20 to 27 kg) and measure 30 to 40 inches (76 to 112 cm) long;unlike other species of dogs, they have only four toes. Although the coloring of each dog's coat is distinct, they all have black muzzles and the tips of their tails are white.
Cape hunting dogs have exceptional eyesight and large round ears that provide the dogs with their primary sensory source when stalking prey. They can run up to 37 miles per hour and have an extraordinarily high kill rate (98 percent). Their diet is carnivorous and includes gazelle, zebra, antelope, and kudu; they stay hydrated from the blood of their prey. Cape hunting dogs will not scavenge for food, unlike their sworn enemy,the hyena. Although Cape hunting dogs have a fairly bad reputation with farmers, they very rarely, if ever, hunt livestock and tend to live as far away from humans as possible.
These dogs travel in a family oriented pack and regurgitate meals for members that are unable to join the chase, such as new mothers and injured dogs. The males live together peacefully, but since only the alpha female is allowed to breed, females tend to viciously fight for this honor or leave the pack. The Cape hunting dog is in danger of extinction due to decreased territory, human-caused mortality (mostly poisoning and snaring),and diseases from domestic dogs.