[转]2010 Ruby on Rails 書單 與 練習作業

原帖:http://wp.xdite.net/?p=1754

=========
學習 Ruby on Rails 最快的途徑無非是直接使用 Rails 撰寫產品。而這個過程中若有 mentor 指導以及 code review,學習進度也會加速不少。

但現實生活中並非如此理想,

第一,並不是每個人都有每天必須要以 Rails 撰寫產品的壓力(not a Rails Developer)。

第二,沒有循序漸進的入門途徑以及沒有 mentor。(Framework 進展太快,導致現有書籍版本跟不上進度,另外具有經驗的 mentor 太少,有的話也沒興趣回答過於初階的問題)

最近幾個月都在訓練 Rails Developer,零碎的東西講了不少遍。懶得一次次重講基礎的東西和開訓練菜單,乾脆整理成文字,以後新人就直接看這篇…

新人需要具備的「一般」基礎技能:

  1. 對 Git 的觀念與技巧掌握。
  2. 對 VIM / Textmate 的基本開發技巧掌握。
  3. 熟悉 Linux Command Line 的操作。

* Git

書單

Peepcode 的 GitPro Git

練習

上 Github 開啟一個專案,練習 git commit , git push , git pull, git branch , git checkout , git merge

* Editor

書單

c9s 的 VIM Hacks 與 Oreilly 的 精通 vi 與 vim 與 Pragmatic 的 TextMate: Power Editing for the Mac

練習

vgod 的 給程式設計師的Vim入門圖解說明 全部練習一遍

* Linux CLI

書單與練習:

Peepcode 的 Meet the Command LineAdvanced Command Line 全部練過一遍

=====

新人需要具備的 Rails 基礎技能:

  1. 可手刻 CRUD ( Create / Read / Update / Delete ) 並且理解 CRUD 中的 params 傳遞方法
  2. route 中 resources 觀念配合 model 裡 has_many 的設計,理解並熟悉 RESTful 觀念。
  3. route 的優先順序與 routes 中 resource / namespace 的實作。
  4. named_scope 、 counter_cache、before_filter
  5. plugin 的使用:restful-authenticationwill_paginatepaperclip
  6. rake 原理以及撰寫 task
  7. ruby on rails 的 production setup 與撰寫 capistrano recipes

書單:(案頭必備)

Ruby Programming — 向 Ruby 之父學程式設計
Ruby for Rails – Rails 開發者必備的 Ruby 學習手冊 (英文新版: The Well-Grounded Rubyist )
碼上就會:Rails敏捷開發網站 (英文新版: Agile Web Development with Rails, Third Edition )
The Rails Way
Ruby Pocket Reference
Rails Recipes
Advanced Rails Recipes: 84 New Ways to Build Stunning Rails Apps

線上工具:(必加書籤)

Ruby API : StringArrayHash
APIDock : Ruby on Rails

練習作業:

(1)開發一個簡易論壇系統。系統要有 Forum 與 Post 兩個 model,寫出 CRUD 介面,並且文章網址是使用 http://example.org/forum/1/post/2 這種表示。

        吸收觀念:

        * CRUD & migration
        * has_many 與 belongs_to
        * resources 與雙層 resources
        * before_filter : find_event

        參考資料:
        
        * 深入淺出 RoR (4-3) – RESTful 與 CRUD action
        * ihower training : Ruby on Rails 入門

( 2)使用者必須能夠 註冊 / 登入,登入後才可以發表 Post,不然只能瀏覽。只有自己的 Post 才能進行修改與刪除。

        吸收觀念:

        * routes 優先權與 route alias
        * plugin 安裝與使用
        * before_filter : login_required
        * session : current_user
        * attr_accessible / attr_protected        

        參考資料:

        * restful-authentication

( 3)論壇的文章要能夠分頁,每一頁 20 筆,每一個論壇要秀出現在論壇裡有多少 post 數量。可用 params 配合 named_scope 在文章列表排序。

        吸收觀念:

        * pagination
        * counter_cache
        * named_scope :recent

        參考資料:
        
        * will_paginate
        * Railscast : Counter Cache Column
        * Railscast : named_scope

( 4)每篇文章可以上傳附件

        吸收觀念:

        * form_for multipart

        參考資料:

        * paperclip

( 5)Admin 可以刪改所有文章,建立一個後台做這件事。網址是 http://example.org/admin/。只有身分是 admin 的人可以進後台。admin 的判別方是 column 裡加一個 boolean,判斷是否 admin。這個 attribute 必須用 attr_accessible / attr_protected 保護。

        吸收觀念:
        
        * route : namespace
        * before_filter : require_is_admin

        參考資料:

        * Namespaces added to routes

( 6)用 Rake 撰寫自動化步驟,生假資料。寫一個 rake 可以達成以下步驟:「砍 db => 建 db => 跑 migration => 生種子資料」,另一個 rake 是生假文章與假論壇。

        吸收觀念:

        * rake -T
        * rake db:drop ; rake db:create ; rake db:migrate ; rake db:seed
        * rake dev:fake ( 自己寫 namespace : dev, 裡面放一個 task 叫做 fake,fake 資料用 Populator 生)

        參考資料:

        * Ruby on Rails Rake Tutorial (aka. How rake turned me into an alcoholic)
        * What’s New in Edge Rails: Database Seeding

( 7)在租來的 VPS 上面建置 Ruby on Rails production 環境,使用 Ruby Enterprise 與 mod_rails。使用 capistrano 佈署 application。

        吸收觀念:

        * cap deploy:setup , cap deploy , cap deploy:rollback , cap deploy:restart

        參考資料:

        * rails-nginx-passenger-ubuntu
        * AWDR3 的 deploy 章節 , Ruby Pocket Reference 的 capistrano 章節

===

PS. 實際測試的結果是,完全不懂 Ruby on Rails 的新人,從頭帶過大概兩週可以練完這一份作業。

原文地址:https://www.cnblogs.com/lidonghao/p/3466671.html