2014-04-29 51 views
1

我試圖做出在Rails API相匹配這些路線的AngularJS $resource

search_notes GET /notes/search/:term(.:format) lesson_notes/notes#search 
     notes GET /notes(.:format)    lesson_notes/notes#index 
       POST /notes(.:format)    lesson_notes/notes#create 
      note GET /notes/:id(.:format)   lesson_notes/notes#show 
       PATCH /notes/:id(.:format)   lesson_notes/notes#update 
       DELETE /notes/:id(.:format)   lesson_notes/notes#destroy 

這是我現在,這不工作:

LessonNotes.factory("Note", ["$resource", function($resource) { 
    return $resource("lesson_notes/notes/:id:action/:term", { 
     id: "@id", 
     action: "@action", 
     term: "@term" 
    }, { 
     query: { method: 'GET', params: {}, isArray: true }, 
     update: { method: 'PATCH' }, 
     destroy: { method: 'DELETE' }, 
     search: { method: 'GET', params: { 
      action: 'search', 
      term: '@term' 
     }, 
     isArray: true 
     } 
    }); 
    } 
]); 

這裏是我的錯誤:我的服務成立心病

"NetworkError: 404 Not Found - http://localhost:3000/lesson_notes/notes/search?0=i&1=n&2=t&3=r&4=o&5=d&6=u&7=c&8=e" 

回答

0

原來rectly但我打電話的搜索錯誤:

這是我錯誤

var results = Note.search($scope.searchTerm); 

這是一個正確

var results = Note.search({term: $scope.searchTerm}); 

順便說一句,這個代碼片斷真的幫助解決這個問題:https://coderwall.com/p/rd0c8w