Вот так выглядит мой products.index
:
Когда я нажимаю ссылку «Создать продукт». Он отправляет меня к /products/new
. Я вижу там форму, но не отправляю ее, вместо этого нажимаю кнопку «Отмена». У меня есть действие в моем контроллере, которое перенаправляет меня на страницу products.index
.
actions: {
cancel: function() {
this.transitionToRoute('products.index');
return false;
}
}
В /products
я вижу:
Что является пустым продуктом... В БД в API нет продуктов. Обновляю страницу, и пустой товар уходит. Что тут происходит?
Полный код:
// app/routes/products/index.js
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
return this.store.find('product');
}
});
// app/routes/products/new.js
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
return this.store.createRecord('product');
},
});
// app/controllers/select-addresses/new.js
export default Ember.ObjectController.extend({
actions: {
cancel: function() {
this.transitionToRoute('products.index');
return false;
}
}
});
// app/templates/products/index.hbs
<h1>Products index</h1>
<p>{{#link-to 'products.new'}}Create product{{/link-to}}</p>
<ul>
{{#each}}
<li>
{{#link-to 'products.show' this}}<strong>{{name}}</strong>{{/link-to}}
<br />Description: {{description}}
<br />Amount in cents: {{amountInCents}}
<br />{{link-to 'Edit' 'products.edit' this}} · <a href="#" {{action "delete" this}}>Delete</a>
<br /><br />
</li>
{{/each}}
</ul>
// app/templates/products/new.hbs
<h1>Add a new friend</h1>
<form {{action "save" on="submit"}}>
<p>
<label>Name:
{{input value=name}}
</label>
{{#each error in errors.name}}
<br />{{error.message}}
{{/each}}
</p>
<p>
<label>Description:
{{input value=description}}
</label>
{{#each error in errors.description}}
<br />{{error.message}}
{{/each}}
</p>
<p>
<label>Amount in cents:
{{input value=amountInCents}}
</label>
{{#each error in errors.amountInCents}}
<br />{{error.message}}
{{/each}}
</p>
<p>
<label>Status:
{{input value=status}}
</label>
{{#each error in errors.status}}
<br />{{error.message}}
{{/each}}
</p>
<input type="submit" value="Save"/>
<button {{action "cancel"}}>Cancel</button>
</form>
{{outlet}}