Incorrect POST using backbone.js
Following these instructions http://robertogds.com开发者_如何学运维/post/3324511589/howto-backbone-js-using-rails-3
The issue/error is that the content is never saved to the db. Using Firebug it appears that the POST json request is incorrect: content "empty todo..." done false
text "test"Basically, the backbone.js event fires a json update that takes the input data ("test") and creates a new model attribute "text" instead of updating the "content" data attribute...
Any thoughts?
Are you calling save on the Backbone.js model like this:
t = new Todo;
t.set({ 'content' : 'test' });
t.save();
Or are you doing this:
t = new Todo;
t.save({ 'content' : 'test' });
Also is there any output from the web server into console when you try and save the model? That may help narrow down where the issue is.
It appears that the author of that post forgot a few steps. The todos.js file needed to include some changes to make sure the :text variable (in the backbone.js todo example) was changed to :content
for example the setText function
var text = this.model.get('content');
the close function
// Close the `"editing"` mode, saving changes to the todo.
close: function() {
this.model.save({content: this.input.val()});
$(this.el).removeClass("editing");
},
and the createOnEnter function
// create new **Todo** model persisting it to *localStorage*.
createOnEnter: function(e) {
var text = this.input.val();
if (!text || e.keyCode != 13) return;
Todos.create({content: text});
this.input.val('');
},
精彩评论