如何从angularjs调用具有特定id的rails控制器

时间:2015-11-05 08:07:22

标签: ruby-on-rails angularjs

我正在使用angularjs和rails,我想像这样调用rails controller

.controller('SongController', ['$scope','FileUploader','$stateParams',function($scope, FileUploader,$stateParams) {

     $scope.uploader = new FileUploader({url: '/events/$stateParams.id/playlists'});

}]);

$ stateParams.id应该被event_id替换为1或2,url就像

/events/1/playlists

但事实并非如此

它给了我以下错误

No route matches [POST] "/events/$stateParams.id/playlists"

如何拨打路线。

1 个答案:

答案 0 :(得分:1)

您需要插入实际ID:

.controller('SongController', ['$scope','FileUploader','$stateParams',function($scope, FileUploader,$stateParams) {
   $scope.uploader = new FileUploader({url: '/events/' + $stateParams.id + '/playlists'});
}]);