我目前正在尝试研究如何使用 Angular JS 和 Sinatra 删除记录。目前该代码会引发内部 500 服务器错误。我在网上四处寻找有关如何正确执行此操作的教程,但找不到任何相关的内容。
我的代码如下:
应用程序.rb
#Delete download
#not working...
delete '/view1/downloaddelete' do
ng_params = JSON.parse(request.body.read)
@download = Download.get(ng_params)
if @download.destroy
{:success => "ok"}.to_json
#log to console if download delete is successful
puts "download delete successful"
else
halt 500
#log to console if download delete is unsuccessful
puts "download delete unsuccessful halt 500"
end
end
下载.html
<p>Manage downloads</p>
<ul>
<li ng-repeat="item in items">Title: {{item.title}}, ID: {{item.downloadID}}<a ng-controller="MyCtrl3" ng-click="deletedownload({{item.downloadID}})">Delete</a></li>
</ul>
控制器.js
//not working...
app.controller('MyCtrl3', ['$scope', '$http', function ($scope, $http) {
$scope.downloaddeleteid = {};
$scope.deletedownload = function() {
$http({
method : 'DELETE',
url : '/view1/downloaddelete',
data : $scope.downloaddeleteid
});
}
console.log($scope.deletedownload);
}]);
任何帮助将不胜感激。