目前,我完成了多个UI选择功能,可以预先选择多个项目。
但是loan_plan.careers
存储数组的对象以启用预先选择的功能。
因此,POST请求将在params中objects of array
而不是数组的id。
我如何才能将POST请求安装在ruby的rails轨道上?
因为ROR希望params应该是loan_plan.career_ids = [2,4,56]
这是我目前的解决方法,它闻起来很糟糕。有什么好建议吗?
$scope.$watch('loan_plan.careers', function(new_val, old_val) {
if($scope.loan_plan){
$scope.loan_plan.career_ids = _.map( new_val , function(num) { return num.id; });
}
});
<ui-select multiple ng-model="loan_plan.careers" theme="bootstrap" ng-disabled="disabled">
<ui-select-match > {{$item.name}} </ui-select-match>
<ui-select-choices repeat="option in careersOptions | propsFilter: {name: $select.search} ">
<div ng-bind-html="option.name | highlight: $select.search"></div>
<small>
<span ng-bind-html="''+ option.description | highlight: $select.search"></span>
</small>
</ui-select-choices>
</ui-select>
'use strict';
angular.module('LoanPlanModule', [])
.factory('LoanPlanService', ['$resource',
function($resource, $http) {
var LoanPlan = $resource('/api/v1/banks/:bank_id/loan_plans/:loan_plan_id', {
bank_id: '@bank_id',
loan_plan_id: '@loan_plan_id'
}, {
update: { method:'PUT' },
create: { method: 'POST' },
delete: { method: 'DELETE'}
});
return LoanPlan;
}
]);