Rails Best Practices Gem: 靜態分析Rails程式碼

Rails Best Practices Gemflyerhzm 根據我的 Rails Best Practices 演講的內容,所作出來的靜態分析程式,可以幫助你快速找到一些可能可以改善的地方。

透過 sudo gem install rails_best_practices –source gemcutter.org 安裝之後,只要執行 rails_best_practices . 就會開始分析你的程式,十分神奇。

這個 gem 也被 Ruby5 – Episode #28Rails Envy Podcast – Episode 102InfoQ China 等介紹。

校園自由工作坊-Ruby 初探 @ 清華大學資工系

Update (2010/12/3): 本活動 12/7 才會開放報名。

又要開課了,和上一回類似的課程內容,這次 OSSF 和清大資工系合辦,時間地點是 12/23 在清華大學 :)

這次真的是大學生了,準備來把範例改成瞇圖程式(?)
anyway,能夠回母校上點課,真是開心 :)

Why “Not use default route”?

In my Rails Best Practices slides, I only give simple code without any description (unless you heard my talk :p), so let me explain here.

my point is: “If you use RESTful design, you should NOT use default route.” Why?

For example:


map.resources :users
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'

You expect only “PUT /users/1” will update user data, but because you keep default route, so “GET /users/update/1?user[email]=foobar@example.org” still works!!

In the same way, “GET /users/create” and “GET /users/destroy/1” works too!! Even worse, the latter can create/update/destroy data without Request Forgery Protection :/ Rails does not check CRSF for HTTP GET.

Conclusion: Remove default route, use purely resource-based routes and named routes for special purpose.

部落格換新網址 ihower.tw

心血來潮,買了新的網址 ihower.tw,即刻生效。
原來的 ihower.idv.tw 之前就買到 2012 年了,所以暫時不會有什麼影響,也用了以下的 Apache 設定把流量都轉到新網址:


<VirtualHost *:80>
ServerName ihower.idv.tw
ServerAlias www.ihower.idv.tw
RedirectMatch 301 ^(.*)$ http://ihower.tw$1
</VirtualHost>

BTW,測試了一下,新的網址大陸應該可以直接連,(暫時?)毋須翻牆。