現在、Angular でフォームを更新し、更新を Sinatra にプッシュする際に問題が発生しています。
次のようになっています。
- クリックすると、現在のアイテムを編集するためのフォームが表示されます (アイテム スコープから各フィールドの現在のデータが表示されます)。
- 送信時に、別のスコープ (updateinfo) への更新を試みています。よくわかりませんが、マルチスコープまたは 1 つのスコープを使用して更新できるようにする方法が必要ですか?
- 現在、スクリプトは正しい downloadID パラメータを送信していますが、送信されたスコープからの JSON は、私が信じているように正しくありません。
- また、Sinatra の app.rb 構文が正しいかどうかもわかりません。これらのフレームワークに慣れていない人にとっては、役立つドキュメントをオンラインで見つけるのが困難でした。
誰かがそれを助けることができれば、それは非常に高く評価されます.
downloads.html
<div ng-show="showEdit">
<form ng-submit="updateinfo(item.downloadID); showDetails = ! showDetails;">
<div class="input-group"><label name="title">Title</label><input type="text"
ng-model="item.title"
value="{{item.title}}"/></div>
<div class="input-group"><label name="caption">Download caption</label><input type="text"
ng-model="item.caption"
value="{{item.caption}}"/>
</div>
<div class="input-group"><label name="dlLink">Download link</label><input type="url"
ng-model="item.dlLink"
value="{{item.dlLink}}"/>
</div>
<div class="input-group"><label name="imgSrc">Image source</label><input type="url"
ng-model="item.imgSrc"
value="{{item.imgSrc}}"/>
</div>
<!-- download live input types need to be parsed as integers to avoid 500 internal server error -->
<div class="input-group"><label name="imgSrc">
<label name="dlLive">Download live</label><input type="radio" ng-model="download.dl_live"
value="1"/>
<label name="dlLive">Not live</label><input type="radio" ng-model="download.dl_live"
value="0"/></div>
<div class="input-group"><label name="imgSrc"><input type="submit"/></div>
</form>
controllers.js
$scope.loadData = function () {
$http.get('/view1/downloadData').success(function (data) {
$scope.items = data;
});
};
$scope.loadData();
$scope.updateinfo = function(downloadID) {
id = downloadID
var result = $scope.items.filter(function( items ) {
return items.downloadID == id;
});
console.log(result);
updatedata = $scope.items
$http({
method : 'PUT',
url : '/view1/downloadedit/:downloadID',
data : result
});
};
app.rb
#edit download
put '/view1/downloadedit' do
puts 'angular connection working'
ng_params = JSON.parse(request.body.read)
puts ng_params
@download = Download.update(ng_params)
end