My index view is pulling all the models from database before the update is carried out is there any way to make sure these actions are synchronised. the model is updated and shows up in index page after a refresh here is the code
app = angular.module('enterprise',["ngResource"])
.config(['$routeProvider','$locationProvider','$httpProvider', ($routeProvider,$locationProvider,provider )->
$locationProvider.html5Mode(true)
provider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content')
$routeProvider.when('/', {templateUrl: '<%=asset_path('list.html') %>', controller: AppCtrl})
$routeProvider.when('/new', {templateUrl: '<%=asset_path('edit.html') %>', controller: NewCtrl})
$routeProvider.when('/edit/:id', {templateUrl: '<%=asset_path('edit.html') %>', controller: EditCtrl})
$routeProvider.otherwise({redirectTo: '/'})
]
app.factory "People", ["$resource",($resource)->
$resource("/people/:id", {id:"@id"},{update: {method:"PUT"}}, {})
]
@AppCtrl=["$scope","People",($scope, People)->
$scope.crew = People.query()
]
@NewCtrl=["$scope","$location", "People",($scope, $location, People) ->
$scope.save = ->
person = People.save($scope.person)
$location.path("/")
]
@EditCtrl=["$scope", "$location", "$routeParams","People",($scope, $location, $routeParams, People)->
$scope.person = People.get({id:$routeParams.id})
$scope.save = ->
person = People.get({id:$routeParams.id }
, ->
person.name = $scope.person.name
person.description = $scope.person.description
person.$update()
)
$location.path("/")
]
any advice on ensuring model is updated before returning to index view
Put $location.path("/") in the People resource's callback function. $resource actions have success/failure callbacks.