我一直在:
无法验证CSRF令牌的真实性 在2ms内完成422个不可处理的实体(ActiveRecord:0.0ms)
我正在尝试发出$ http请求来发布新的数据库条目。使用Angular over RoR。
在我的Angular控制器中:
...
$scope.createArea = function(data){
var areaData = $scope.areaData;
var url = '/locations/' + locationService.id + '/floors/' + floorService.id + '/areas.json'
$http({
url: url,
method: 'POST',
contentType: "application/json",
data: areaData
});
};
我的表格:
<div class="form-horizontal" id="new-area" ng-controller="mapsController">
<form ng-submit="createArea(areaData)">
<div id="name-group" class="form-group">
<label>Name</label>
<input type="text" name="name" class="form-control" placeholder="Area Name" ng-model="areaData.name" /><br />
<label>Group</label>
<select class="form-control">
<option ng-repeat="group in groups" value="{{group.id}}" ng-model="areaData.groupID">{{group.name}}</option>
</select>
</div>
<button type="submit" class="btn btn-default">Create</button>
</form>
</div>
在我的rails控制器中:
def create
respond_to do |format|
format.json
end
end
答案 0 :(得分:1)
找到答案:添加了gem&#39; angular_rails_csrf&#39;到我的gemfile。文档:https://github.com/jsanders/angular_rails_csrf