RailsCast 筆記[不完整]

走過了彎路,看過了那些粗製濫造、過時、或者至少不夠有深度的書之後,才知道:Ruby for Rails+The Ruby Programming Language+Agile Web Development with Rails+RailsCast這一個套裝,纔是學習Ruby on Rails最快最好的途徑。其中RailsCast是免費的視頻,目前已有152集。它的最大價值是讓你直觀地感覺到Rails中隱藏的力量。如果你整個 系列走下來,當你遇到一個問題時,你知道在Rails中大約可以以什麼方式做到。當你心中有了明確的方向,只需要手持API Reference Manual,就可以解決一路上的問題。

 

寒假到現在用Ruby on Rails爲導師完成了一個小型教學網站,主要有課程管理、博客發表、課件上傳下載、作業佈置和上交以及留言系統。以後可能再在這裏添加一份完整的功能介 紹吧。這個網站傾注了我大量的心血,解決了無數稀奇古怪的bug,對網站也做了許多次重構,實現了許多細小的功能,經過這番歷練,我終於對基於MVC的網 站開發有了一個較爲全局的認識,對Rails也非常熟悉了,也部分實踐了我在《Web 2.0網站開發心得》中對Ajax的適度使用的原則。遺憾的是,由於時間的緣故,我無法把所有我想實現的特性都實現,項目已經需要投入實際使用當中了。希 望它在性能和穩定性方面能夠不讓人失望吧。以後再添加一個尚未全部實現的特性列表到這裏吧。如果有時間,我想把整個網站在Ruby 1.9 on Rails 2.3下用BDD的方式重新開發一次,對網站整體做更大的重構,同時完整地使用Git來進行版本管理,同時藉助於自己計劃編寫的GitRoller來製作 一系列視頻。

 

主要使用的技術:

 

Ruby 1.8.6 on Rails 2.2 . Most of the ideas are inspired by Rails Cast

 

Rails plugins or gems used:

JavaScript Library Used:

Layout based on YAML . Some CSS are stolen from WebCredible and Firefox Plugins(Germany)

 

1.         新特性介紹

2.         JavaScript、Ajax

3.         電子商務

4.         Git、Contribute

5.         DIY

6.         分頁、預覽、搜索、附件

7.         部署

8.         REST、路由

9.         控制器

10.     用戶、Session、Authentication相關

11.     視圖

12.     重構

13.     後臺Rake

14.     模型、數據庫層

15.     關聯

16.     Scope、group

17.     性能

18.     Log、調試

19.     測試

20.     設置

21.     安全

以下列表基於時間倒序整理。

新特性介紹

152. Rails 2.3 Extras
151. Rack Middleware
150. Rails Metal
149. Rails Engines
148. App Templates in Rails 2.3
140. Rails 2.2 Extras

JavaScript 、Ajax

147. Sortable Lists
136. jQuery
114. Endless Page
103. Site Wide Announcements
88. Dynamic Select Menus
45. RJS Tips
44. Debugging RJS
43. AJAX with RJS

電子商務

146. PayPal Express Checkout
145. Integrating Active Merchant
144. Active Merchant Basics
143. PayPal Security
142. PayPal Notifications
141. PayPal Basics

Git 、Contribute


113. Contributing to Rails with Git
105. Gitting Rails 2.1 RC1
96. Git on Rails
50. Contributing to Rails
36. Subversion on Rails

DIY

135. Making a Gem   製作一個Gem。你對Rails的擴充,只要符合一定的文件佈局,就能又可以當插件用,又可以當gem用。
33. Making a Plugin   製作插件的方法。define_method、read_attribute、instance_variable_set等等。
62. Hacking ActiveRecord   如何爲ActiveRecord增加方法。
58. How to Make a Generator  做一個自己的Generator。本質:erb。

分頁、預覽、搜索、附件

120. Thinking Sphinx   全文搜索
111. Advanced Search Form  多個條件綜合搜索。本質:動態merge hash。
37. Simple Search Form 單一條件搜索。本質:SQL之LIKE。
38. Multibutton Form  預覽功能。本質:在同一個action中根據params的不同而展現不同的行爲。
51. will_paginate 分頁。
134. Paperclip  DSL風格輕鬆附件上傳、驗證、縮略圖生成。我探索了的高級用法:任意多個附件、附件重命名等。

部署

133. Capistrano Tasks
123. Subdomains
122. Passenger in Development

REST 、路由

34. Named Routes 有名路由。例如對於:controller => :users, :action => new,可以命名爲login,這樣url就是/login了,一種美化。
79. Generate Named Routes 對map做send,動態生成named route,防止重名。
63. Model Name in URL 讓url中可以包含有意義的信息,而不只是id。
70. Custom Routes  讓url中可以包含多個參數作爲路徑,如2007/01/08。本質:":year/:month/:day"。
46. Catch-all Route  讓url中此後的全部路徑成爲一個數組。例如對於"/*path","/a/b/c"
的params[:path]就是['a','b','c']。


35. Custom REST Actions
139. Nested Resources
95. More on ActiveResource
94. ActiveResource Basics
92. make_resourceful
117. Semi-Static Pages

 

控制器

131. Going Back  重定向到用戶之前瀏覽的頁面。
87. Generating RSS Feeds 創建RSS。
78. Generating PDF Documents 創建PDF。
77. Destroy Without JavaScript  在沒有javaScript的情況下,如何讓用戶確認刪除。

用戶、Session 、Authentication相關



84. Cookie Based Session Store 沒什麼意思。討論了一下session的存儲機制。
19. Where Administration Goes  管理員與普通用戶共享一個界面。額外收穫:action_model_path(var_model)。
20. Restricting Access   根據是否管理員顯隱一些部分,以及阻止一些action的perform。helper_method :admin?、before_filter :authorize, :except => :index。
21. Super Simple Authentication  管理員的簡單認證。通過session等各種方式判斷是否管理員。session的創建與銷燬。
67. restful_authentication  介紹了restful_authenticate這個插件,非常好用的多用戶管理。
68. OpenID Authentication  基於OpenID的認證。
82. HTTP Basic Authentication  內嵌在http協議中的基於用戶名和密碼的簡單認證。2.3現在實現了HTTP Digest Authentication,保密程度更高。
119. Session Based Model  可以讓非註冊用戶在發表留言後一定時間內仍然可以回來修改留言。

65. Stopping Spam with Akismet  阻止垃圾留言。
61. Sending Email  發送郵件。
124. Beta Invitations 邀請系統。

視圖

132. Helpers Outside Views
125. Dynamic Layouts
118. Liquid
100. 5 View Tips
69. Markaby in Helper
64. Custom Helper Modules
40. Blocks in View
32. Time in Text Field
31. Formatting Time
30. Pretty Page Title
18. Looping Through Flash
8. Layouts and content_for
7. All About Layouts

重構

91. Refactoring Long Methods
75. Complex Forms Part 3
74. Complex Forms Part 2
73. Complex Forms Part 1
101. Refactoring Out Helper Object
12. Refactoring User Name Part 3
11. Refactoring User Name Part 2
10. Refactoring User Name Part 1
80. Simplify Views with Rails 2.0
55. Cleaning Up the View
99. Complex Partials

後臺Rake

66. Custom Rake Tasks  如何寫Rake任務。
127. Rake in Background   在後臺運行Rake來執行耗時任務。
128. Starling and Workling   通過Rake的後臺隊列來異步執行Rakes。
129. Custom Daemon   後臺的daemon。和128的區別就像cron和at的區別。
130. Monitoring with God  監視daemon。

模型、數據庫層

126. Populating a Database
109. Tracking Attribute Changes
121. Non Active Record Model
112. Anonymous Scopes
108. named_scope
107. Migrations in Rails 2.1
83. Migrations in Rails 2.0
16. Virtual Attributes
15. Fun with Find Conditions
14. Performing Calculations on Models
4. Move Find into Model
3. Find Through Association
2. Dynamic find_by Methods
59. Optimistic Locking
41. Conditional Validations

關聯

52. Update through Checkboxes   一對多。通過checkbox來更新關聯的items。"item_ids[]"。
57. Create Model Through Text Field  一對多。Choose_or_create。collection_select。
102. Auto-Complete Association   一對多。Find_or_create_by。自動完成。
17. HABTM Checkboxes  多對多。產品與Catagory。
47. Two Many-to-Many  多態的多對多。

Scope 、group

76. scope_out
42. with_options
5. Using with_scope
29. group_by Month
28. in_groups_of
6. Shortcut Blocks with Symbol to_proc

 

性能

1. Caching with Instance Variables  用||=的方式緩存查詢結果。

115. Caching in Rails 2.1  用fectch cache的方式緩存結果。
137. Memoization  用memorize的方式緩存結果。

89. Page Caching 緩存頁面。caches_page。如何用sweeper來清除過期頁面。expire_page。

93. Action Caching  緩存動作。

90. Fragment Caching  緩存一個partial、或者說片段。

 
98. Request Profiling  如何測試網站的性能瓶頸。
97. Analyzing the Production Log  分析生產狀態下運行的網站的日誌查找網站的性能瓶頸。

23. Counter Cache Column  例如,緩存博客擁有的評論數目。這樣顯示博客目錄時,不必爲每一個博客COUNT一次評論數目。
22. Eager Loading   例如,一個課程擁有多個課件,如果find時使用了:include => :課件, :select => 'id, title',顯示課程目錄時,也可以同時讀取相關課件的標題信息。用於減少一個頁面發起SQL查詢的數目。

Log 、調試

24. The Stack Trace 如何理解堆棧追溯。
9. Filtering Sensitive Logs 在日誌中過濾掉敏感信息。
104. Exception Notifications  當網站發生問題,發個郵件給管理員。exception_notifier和exception_logger。
86. Logging Variables  如何在日誌中輸出變量的值。eval(..., binding)。
56. The Logger  如何自定義和查看日誌。
54. Debugging with ruby-debug  如何調試Ruby。
53. Handling Exceptions  用ruby的異常機制處理異常。
49. Reading the API  比較好用的Rails文檔
48. Console Tricks  使用控制檯script/console的技巧。

測試

116. Selenium
81. Fixtures in Rails 2.0
71. Testing Controllers with RSpec
60. Testing without Fixtures

設置

85. YAML Configuration File  如何讀取自己的YAML配置文件。我嘗試了的高級使用:根據用戶設置生成YAML配置,保證網站重啓後用戶的設置仍然有效。
72. Adding an Environment   除了通常的development、production、test三種網站運行環境之外,添加一個staging環境用於演示。
138. I18n    國際化。
106. Time Zones in Rails 2.1  設置時區。或讓用戶自己指定時區。
39. Customize Field Error    自定義當表單提交驗證失敗時顯示錯誤信息的方式。
110. Gem Dependencies  通過config.gem指定網站依賴的gem,對其存在進行驗證,並可通過rake gems:install安裝所需的gem。方便部署。

安全

27. Cross Site Scripting    如何使用h函數和sanitize函數來消除用戶提交內容中帶來安全風險的javascript腳本。
26. Hackers Love Mass Assignment   通過attr_protected和attr_accessible防止黑客可以給某些字段賦值。
25. SQL Injection   通過使用?來防止SQL注入式的攻擊。
13. Dangers of Model in Session  千萬不要把模型保存在session裏面。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章