I have been trying to fetch the id of this Select helper all day, and still noting but nil's and undefined... I just want the product_id to be set to the value in the Select which is being set fine in the template....
// Models
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 />
...
// controller
Amber.ConsumptionsNewController = Ember.ObjectController.extend ({
products: function() {
return this.store.find('product')
}.property('product')
});
// Route + routes
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 Serializers
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
All the other values are being saved alright... but product_id is never set. Very frustrating when I can actually see the ID being bound to the option value in the html:
<select id="ember983" class="ember-view ember-select">
<option id="ember996" class="ember-view" value="1">A-Product</option>
I hope someone can help.. Have been stuck here for waaayyy to long now :/