Значения, которые я передаю во входные данные моей формы, возвращают null.
Modal-template:
<script type="text/ng-template" id="new-label.modal.html">
<div class="modal-header">
<button type="button" class="close" ng-click="vm.cancel()">
<span aria-hidden="true">x</span>
</button>
<h4>Nova etiqueta</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label for="new_label">Nome</label>
<input type="text" id="new_label" name="new_label" class="form-control" ng-model="vm.newLabel.name">
</div>
<div class="form-group">
<label for="label_products"><%= t('products') %></label>
<ui-select ng-cloak style="display: inline-block; width: 100%; position: relative; min-height: 34px" multiple ng-model="vm.newLabel.products" theme="bootstrap" close-on-select="true" title="<%= t('tag_products_with_label') %>" spinner-enabled="true">
<ui-select-match placeholder="<%= t('tag_products_with_label') %>">
<span>{{ $item.description }}</span>
</ui-select-match>
<ui-select-choices repeat="product in vm.productSearch.products track by product.id" refresh="vm.searchProducts($select.search)" refresh-delay="330">
{{ product.description }}
</ui-select-choices>
</ui-select>
</div>
<div class="checkbox">
<label>
<input type="checkbox" ng-model="vm.newLabel.show_on_fid">
<%= t('shown_on_fid') %>
</label>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-disabled="vm.saving" type="button" ng-click="vm.save()">Salvar</button>
<button class="btn btn-secondary" ng-disabled="vm.saving" type="button" ng-click="vm.cancel()"><%= t('label_modal.cancel') %></button>
</div>
</script>
Modal- js:
function LabelsController($scope, $q, $timeout, $http, $uibModal) {
var self = this;
this.newLabel = {
name: '',
products: [],
show_on_fid: []
};
this.productSearch = {};
this.saving = false;
this.loading = false;
this.labels = {};
this.page = 1;
this.loadingPromise = null;
this.allTagsSelected = false;
this.createLabel = function () {
$uibModal.open({
templateUrl: 'new-label.modal.html',
controllerAs: 'vm',
controller: ['$uibModalInstance', function ($uibModalInstance) {
var vm = this;
vm.searchProducts = function (filter) {
if (filter.length < 3) {
var defer = $q.defer();
defer.resolve();
return defer.promise;
}
return $http({
url: '/manager/products/get_products',
method: 'GET',
params: {
filter: filter,
page: 1
}
}).then(function (response) {
vm.productSearch = response.data;
});
};
this.save = function () {
var newLabel = angular.extend({}, self.newLabel);
newLabel.products = newLabel.products.map(function (product) {
return product.id;
});
self.saving = true;
$http({
url: '/manager/labels.json',
method: 'POST',
data: {
label: newLabel
}
}).then(function () {
$.toast('Etiqueta criada com sucesso.', {type: 'success'});
self.newLabel = {
name: '',
products: [],
show_on_fid: [],
};
self.saving = false;
$uibModalInstance.close();
}, function () {
$.toast('Houve um problema com a sua requisição. Tente novamente.', {type: 'error', duration: 10000});
self.saving = false;
});
}
this.cancel = function () {
$uibModalInstance.dismiss('cancel');
}
}],
}).result.then(function () {
self.loadLabels();
});
};
Контроллер:
...
def create
current_user_branch = current_user.get_branch_access
@label = Label.create(vendor: @vendor, name: params[:label][:name], show_on_fid: params[:label][:show_on_fid], branch_id: current_user_branch)
@label.products = Product.where(vendor: @vendor, id: params[:label][:products])
render json: {status: :ok}
end
Когда я ввожу имя для своей метки , выберите продукт, отметьте чекбокс и сохраните, на созданной этикетке не будет помечено название или продукт, будет отмечен только чекбокс. Что я делаю не так?