2013-03-28 51 views
4

Rails爲我所依賴的嵌套資源提供了一個淺層選項,否則我會有4或5個嵌套資源,這會非常糟糕。Angular和Rails淺層資源

淺層資源是這樣的:

resources :posts do 
    resources :comments, :only => [:index, :create] 
end 
resources :comments, :only => [:show, :update, :destroy] 

我來到到,當試圖用角資源映射Rails的資源,因爲ngResource只允許一個URI來定義的問題,所以無論是/posts/:post_id/comments/:id/comments/:id

我想讓ngResource允許方法覆蓋URI和插值。例如:

app.factory('Comment', ['ngResource', function ($resource) { 
    $resource('/comments/:id', { 'id': '@id', post_id: '@post_id' }, 
     index: { method: 'GET', url: '/posts/:post_id/comments', isArray: true }, 
     create: { method: 'POST', url: '/posts/:post_id/comments' }, 
     show: { method: 'GET' }, 
     update: { method: 'PUT' }, 
     destroy: { method: 'DELETE' } 
    ); 
}]); 

這是可能的,也許與另一個模塊比ngResource?或者我應該只是建立兩個服務:評論和評論?

+0

順便說一句,對於需要更改資源URL的資源上的成員和集合操作,同樣的問題是有效的。 – 2013-03-28 10:17:11

回答

2

我實際上從github看了角度資源的源代碼,發現當前主控允許動作指定他們自己的url參數。我在我的問題中編寫的例子完全可能與Angular 1.1.4+(尚未發佈)完美結合。

升級到當前角主是解決方案。