看板 Ruby 關於我們 聯絡資訊
※ 引述《ryudo (那很好哇)》之銘言: : 簡單來說, 就是怎樣返回物件數量的統計 這個問題 : URL/ROUTE/ACTION等的設定方式, 有點摸不著頭緒說 : REST在一般狀況下 預設就是index(回傳全部)/show(一筆) 這樣 : 怎樣設定才能單獨回傳該model的count? 加 custom collection 就好了, 例如: map.resources :events, :collection => { :count => :get } 然後在 events controller 多一個 action 是 def count render :text => Event.count end 這樣 /events/count 就可以拿到回傳值了 (helper是 count_events_path) --- 我之前寫的REST投影片應該會有幫助了解 http://ihower.idv.tw/blog/archives/1720 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.43.193.119
godfat:原來是要 rails 的 map.resources 的 generator 用法喔 @@ 04/10 14:23
ryudo:感動..ih大大果真神人也 04/13 14:04