私は一日中この Select ヘルパーの ID を取得しようとしましたが、まだ nil と undefined に注意しています...テンプレートでうまく設定されている Select の値に product_id を設定したいだけです... .
// モデル
Amber.Consumption = DS.Model.extend({
product: DS.belongsTo('product', {async: true}),
quantityUsed: DS.attr('number'),
location: DS.attr('string'),
employeeName: DS.attr('string'),
processed: DS.attr('boolean', {defaultValue: false})
});
Amber.Product = DS.Model.extend({
quantityStock: DS.attr('number'),
product: DS.attr('string'),
consumptions: DS.hasMany('consumption', {async:true})
});
/consumption/new.hbs
<form {{action "create" on="submit"}}>
<div>
<label>Produkt<br />
{{view "select"
content=products
selection=products
optionValuePath="content.id"
optionLabelPath="content.product"
}}
</label>
</div><br />
...
// コントローラー
Amber.ConsumptionsNewController = Ember.ObjectController.extend ({
products: function() {
return this.store.find('product')
}.property('product')
});
// ルート + ルート
Amber.Router.map(function() {
this.resource('products', function() {
this.route('new');
this.route('update', { path: '/update/:product_id' });
this.route('show', { path: '/show/:product_id' });
this.resource('consumptions', function() {
this.route('new');
this.route('show', { path: '/show/:consumption_id' });
})
});
});
Amber.ConsumptionsNewRoute = Ember.Route.extend({
model: function() {
return this.store.createRecord('consumption', {
processed: true,
});
},
actions: {
create: function() {
var newConsumption = this.get('currentModel');
var self = this;
newConsumption.save().then(
function() { self.transitionTo('consumptions') },
function() { }
);
}
}
});
// Railsシリアライザ
class ConsumptionSerializer < ActiveModel::Serializer
attributes :id, :product_id, :quantity_used, :employee_name, :processed, :location
end
class ProductSerializer < ActiveModel::Serializer
attributes :id, :quantity_stock, :product
end
他のすべての値は問題なく保存されています...しかし、product_idは決して設定されません。ID が HTML のオプション値にバインドされているのを実際に見ると、非常にイライラします。
<select id="ember983" class="ember-view ember-select">
<option id="ember996" class="ember-view" value="1">A-Product</option>
誰かが助けてくれることを願っています.. waaayyyから長い間ここで立ち往生しています:/