我希望通过将数据发布到rails服务器来创建新方法,并创建将数据保存到数据库的操作。我正确地发布数据并将数据保存到数据库中。但最后我得500 internal error
。我展示create
动作:
class Api::V1::BolouksController < Api::V1::BaseController
def create
@bolouk = Bolouk.create(bolouk_params)
@bolouk.save
respond_with(@bolouk)
end
private
def bolouk_params
params.require(:bolouk).permit(:boloukcode, :north, :south, :east, :west)
end
end
服务器日志:
Started POST "/api/bolouks.json" for 127.0.0.1 at 2014-08-31 12:36:10 +0430
Processing by Api::V1::BolouksController#create as JSON
Parameters: {"south"=>"76876", "west"=>"46365", "east"=>"987987", "north"=>"897987", "boloukcode"=>"21321", "bolouk"=>{"boloukcode"=>"21321", "north"=>"89798
7", "south"=>"76876", "east"=>"987987", "west"=>"46365"}}
(0.0ms) begin transaction
SQL (0.0ms) INSERT INTO "bolouks" ("boloukcode", "created_at", "east", "north", "south", "updated_at", "west") VALUES (?, ?, ?, ?, ?, ?, ?) [["boloukcode",
"21321"], ["created_at", "2014-08-31 08:06:10.645999"], ["east", "987987"], ["north", "897987"], ["south", "76876"], ["updated_at", "2014-08-31 08:06:10.64599
9"], ["west", "46365"]]
(96.6ms) commit transaction
(0.0ms) begin transaction
(0.0ms) commit transaction
Completed 500 Internal Server Error in 162ms (Views: 1.0ms | ActiveRecord: 96.6ms)
我不知道这个问题,因为当我删除create
行动的所有方法时,我再次获得500 Internal Error
。
class Api::V1::BolouksController < Api::V1::BaseController
def create
end
end
server log
:
Started POST "/api/bolouks.json" for 127.0.0.1 at 2014-08-31 12:40:48 +0430
Processing by Api::V1::BolouksController#create as JSON
Parameters: {"south"=>"543543", "west"=>"76875", "east"=>"4312432", "north"=>"987967", "boloukcode"=>"68987", "bolouk"=>{"boloukcode"=>"68987", "north"=>"987
967", "south"=>"543543", "east"=>"4312432", "west"=>"76875"}}
Completed 500 Internal Server Error in 11ms (Views: 0.0ms | ActiveRecord: 0.0ms)
我无法理解这个问题。问题出在哪儿?我该如何解决500 Internal Error
?
更新问题:
我从angularjs代码发布数据,我在下面添加角度控制器和服务:
'use strict';
var app = angular.module('app');
app.controller('BoloukCtrl', ['$scope','Session', 'Bolouks', 'Secure', function($scope, Session, Bolouks, Secure){
$scope.bolouk = {};
$scope.bolouk.boloukcode = $scope.bolouk.north = $scope.bolouk.east = $scope.bolouk.west = $scope.bolouk.south = "";
$scope.save = function(){
var alaki = Bolouks.create($scope.bolouk);
$scope.bolouk = {};
$scope.bolouk.boloukcode = $scope.bolouk.north = $scope.bolouk.east = $scope.bolouk.west = $scope.bolouk.south = "";
}
}]);
boloukService.js
:
'use strict';
var app = angular.module('boloukService', ['ngResource']);
app.factory('Bolouks', function($resource) {
return $resource('/api/bolouks.json', {}, {
index: { method: 'GET', isArray: true},
create: { method: 'POST' }
});
});
view.html
:
<form ng-submit="save()" class="form-horizontal" role="form">
//I complete bolouk field and then post to angularjs controller and by using service, post to rails server.
</form>