朝練備忘

ごにょごにょと試行錯誤orz

routing

only と expect の差が意味不明。例えば

  resources :hoge :expect => [:index]

だと

                  hoge_index GET    /hoge(.:format)                       hoge#index {:expect=>[:index]}
                             POST   /hoge(.:format)                       hoge#create {:expect=>[:index]}
                    new_hoge GET    /hoge/new(.:format)                   hoge#new {:expect=>[:index]}
                   edit_hoge GET    /hoge/:id/edit(.:format)              hoge#edit {:expect=>[:index]}
                        hoge GET    /hoge/:id(.:format)                   hoge#show {:expect=>[:index]}
                             PUT    /hoge/:id(.:format)                   hoge#update {:expect=>[:index]}
                             DELETE /hoge/:id(.:format)                   hoge#destroy {:expect=>[:index]}

で、

  resources :hoge, only: [:create, :new, :edit, :show, :update, :destroy]

って書くと

                  hoge_index POST   /hoge(.:format)                       hoge#create
                    new_hoge GET    /hoge/new(.:format)                   hoge#new
                   edit_hoge GET    /hoge/:id/edit(.:format)              hoge#edit
                        hoge GET    /hoge/:id(.:format)                   hoge#show
                             PUT    /hoge/:id(.:format)                   hoge#update
                             DELETE /hoge/:id(.:format)                   hoge#destroy

て出力されるんですが、意味不明。別途調べます。

find してレコードなかった場合に空の配列戻して欲しい

find_by_hoge だと無ければ nil なんだけど find_all_by_hoge ってやれば [] が戻ってくるのか。
あと、更新が update_attributes で云々ってことは hidden なソレをフォームに仕込む必要があるのかな。や、んなことしなくても new アクションで仕込んでおけば OK なのか。
そして今、謎の routing error でハマり中。