Wednesday, 15 June 2011

ruby on rails 3 - angularjs synchronise $request to update database before $request.query() is fired on index view -



ruby on rails 3 - angularjs synchronise $request to update database before $request.query() is fired on index view -

my index view pulling models database before update carried out there way create sure these actions synchronised. model updated , shows in index page after refresh here 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 updated before returning index view

put $location.path("/") in people resource's callback function. $resource actions have success/failure callbacks.

ruby-on-rails-3 coffeescript angularjs

No comments:

Post a Comment