my recors are not being saved to the database after being created. I'm just using fixtures. I can see the model on the Ember addon when creating it in the form, but after hitting save, they dissappear and nothing happens. Also, when I select an item on the model.genre select input nothing happens. This is what I did:
/router.js
Router.map(function() {
this.resource('books', {path: '/'});
this.resource('book', {path: '/books/:book_id'});
this.resource('genre', {path: '/genres/:genre_id'});
this.resource('reviews', function() {
this.route('new');
});
});
export default Router;
reviews/new.hbs
<div class='row'>
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="book_title" class="col-sm-2 control-label">Book Title</label>
<div class="col-sm-9">
{{input class="form-control" id="book_title" placeholder="Book Title" valueBinding="model.title"}}
</div>
</div>
<div class="form-group">
<label for="book_author" class="col-sm-2 control-label">Author</label>
<div class="col-sm-9">
{{input class="form-control" id="book_author" placeholder="Author" valueBinding="model.author"}}
</div>
</div>
<div class="form-group">
<label for="book_amazon_id" class="col-sm-2 control-label">Amazon ID</label>
<div class="col-sm-9">
{{input class="form-control" id="book_amazon_id" placeholder="Amazon ID" valueBinding="model.amazon_id"}}
</div>
</div>
<div class="form-group">
<label for="book_review" class="col-sm-2 control-label">Review</label>
<div class="col-sm-9">
{{textarea valueBinding="model.review" class="form-control" id="book_review"}}
</div>
</div>
<div class="form-group">
<label for="book_rating" class="col-sm-2 control-label">Rating</label>
<div class="col-sm-9">
{{view Ember.Select content=ratings valueBinding='model.rating' class="form-control" id="book_rating"}}
</div>
</div>
<div class="form-group">
<label for="book_genre" class="col-sm-2 control-label">Genre</label>
<div class="col-sm-9">
{{view Ember.Select content=genres optionLabelPath="content.name" valueBinding="model.genre" class="form-control" id="book_genre"}}
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default" {{action 'createReview'}}>Save Review</button>
</div>
</div>
</form>
</div>
{{book-details book=model}}
</div>
app/routes/reviews/new.js
export default Ember.Route.extend({
model: function() {
return Ember.RSVP.hash({
book: this.store.createRecord('book'),
genres: this.store.findAll('genre')
});
},
setupController: function(controller, model) {
controller.set('model', model.book);
controller.set('genres', model.genres);
},
actions: {
willTransition: function(transition) {
if(this.currentModel.book.get('isNew')) {
if(confirm("Are you sure you want to abandon progress?")) {
this.currentModel.book.destroyRecord();
} else {
transition.abort();
}
}
}
}
});
app/controllers/reviews/new.js
export default Ember.Controller.extend({
ratings: [5,4,3,2,1],
actions: {
createReview: function() {
var controller = this;
this.get('model').save().then(function() {
controller.transitionToRoute('books');
});
}
}
});
This is the complete code in case it helps: http://ift.tt/1Q3hhos
Any help would be really appreciated. Thanks
Aucun commentaire:
Enregistrer un commentaire