当页面加载时,资源会抛出 404,因为 $resource 正在读取 nil for :city_id。我从 angularjs 开始,所以任何澄清都值得赞赏。
表单条目无法保留,因为此 $resource 还用于 PUT 模型中的条目。
app = angular.module("CityAngular", ["ngResource"])
app.factory "Seal", ["$resource", ($resource) ->
$resource("/cities/:city_id/seals/:id", {city_id: "@city_id", id: "@id"}, {update: {method: "PUT"}})
]
@SealCtrl = ["$scope", "Seal", ($scope, Seal) ->
$scope.seals = Seal.query()
$scope.addSeal = ->
seal = Seal.save($scope.newSeal)
$scope.seals.push(seal)
$scope.newSeal = {}
]