orders
並び順リソースは集合リソースなので:collectionで定義するとよい。
map.resources :user_profile_items, :collection => { :orders => :put }
これを PUT /user_profile_item/{id}/ で処理しようとすると、単純なupdateではすまないので面倒なことになる。正直に、orderを代えたかったら、idを並び順で全部おくってこい、というのが正しいんだと思う。
ちなみに、sortable_element を使うと、order アクションは次のようにかける。
# PUT /components/system/user_profile_items/orders def orders params[:user_profile_items].each_with_index do | item, index | sort_item = WjUserProfileItem.find(item) sort_item.sort_order = index + 1 sort_item.save end render :nothing => true end
で、エラー処理をしていないんだけれど、find メソッドで RecordNotFound がでるときは、たぶん404で返すのは正しくないと思った。ordersは常に存在するリソースで、パラメーターが悪いだけだから400なり、妥当なHTTPコードを返すべきか。