Red > Green > Refactor > Red

cycle is based on desire

Rails routing ; member, collection

member => ID(固有の値)を必要とする。紐づくオブジェクトの一つのメンバーになるから。

ex. 写真集のプレビューページ(5ページ目だとか、8ページ目だとか)

collection => ID(固有の値)は必要としない。それ自体が単一のオブジェクトだから。

ex. 検索

resources :photos do
  member do
    get :preview
  end

  collection do
    get :search
  end
end
       Prefix Verb   URI Pattern                   Controller#Action
preview_photo GET    /photos/:id/preview(.:format) photos#preview
search_photos GET    /photos/search(.:format)      photos#search
       photos GET    /photos(.:format)             photos#index
              POST   /photos(.:format)             photos#create
    new_photo GET    /photos/new(.:format)         photos#new
   edit_photo GET    /photos/:id/edit(.:format)    photos#edit
        photo GET    /photos/:id(.:format)         photos#show
              PATCH  /photos/:id(.:format)         photos#update
              PUT    /photos/:id(.:format)         photos#update
              DELETE /photos/:id(.:format)         photos#destroy

大変よい参考

こういう例えができる人間になりたい

http://stackoverflow.com/questions/3028653/difference-between-collection-route-and-member-route-in-ruby-on-rails