Ruby on rails 通过将Anguarjs与Rails一起使用,获得不匹配[DELETE]错误

Ruby on rails 通过将Anguarjs与Rails一起使用,获得不匹配[DELETE]错误,ruby-on-rails,angularjs,angularjs-routing,Ruby On Rails,Angularjs,Angularjs Routing,创建和查看对象进展顺利。 但是当我尝试添加DELETE函数时。它响应一个错误: Started DELETE "/api/items" for 127.0.0.1 at 2014-05-21 01:15:32 +1000 ActionController::RoutingError (No route matches [DELETE] "/api/items"): actionpack (4.1.0) lib/action_dispatch/middleware/debug_exceptions

创建和查看对象进展顺利。 但是当我尝试添加DELETE函数时。它响应一个错误:

Started DELETE "/api/items" for 127.0.0.1 at 2014-05-21 01:15:32 +1000
ActionController::RoutingError (No route matches [DELETE] "/api/items"):
actionpack (4.1.0) lib/action_dispatch/middleware/debug_exceptions.rb:21:in 
我已经为项目设置了资源,可以在路由表中找到

namespace :api do
  resources :items, defaults: {format: :json}
end

api_capsule GET /api/capsules/:id(.:format)      api/items#show {:format=>:json}
            PATCH    /api/items/:id(.:format)    api/items#update {:format=>:json}
            PUT      /api/items/:id(.:format)    api/items#update {:format=>:json}
            DELETE   /api/items/:id(.:format)    api/items#destroy {:format=>:json}
以下是删除的方法:

application.js.coffee

$scope.delete = ($index) ->
$scope.items[$index].$remove()
$scope.items.splice($index, 1)

controller.rb
def destroy
  respond_with current_user.items.destroy(params[:id])
end

有人知道这些代码有什么问题吗?

根据rails控制台的输出,您正试图向
/api/items
发送一个删除请求,而您应该将其发送到
/api/items/:id

您要求rails删除集合而不是单个项目,rails正确地通知您路由不存在

确保在AngularJS控制器操作中实际设置和/或使用了要删除的ID


确保
$scop.items[$index]
在不正确地构建URL时实际上有一个ID,并确保在执行API请求之前没有执行
splice
调用(可能是因为删除请求是异步的)

您应该编辑问题标题以引用AngularJS,不是Anguarjs-拼写错误令人困惑。