ruby on rails - Backbone fetch not receiving server response -
i'm learning backbone , working through mock twitter tutorial. seems should working, i'm getting undefined object @ point of trying re-render collection view on fetch({reset: true}).
i can see in network resources nicely formatted response rails server- [{id: 1, content: ...},{id: 2..}...] , on. if stop @ breakpoints throughout code - backbone's own success callback, response (or resp in bb's source code) undefined.
also, first stackoverflow post after lurking here , solving problems other folks questions months! wonderful community.
relevant code here:
$(document).ready(function(){ var tweets = new tweetscollection; var stream = new tweetsview({collection: tweets}); stream.render(); $(".container").append(stream.el); tweets.fetch(); stream.addall(); }) var tweetscollection = backbone.collection.extend({ model: tweet, url: 'tweets/recent', parse: function (response) { console.log("in parse: " + response.length) //this logs "in parse: 0" return response; } }) var tweetsview = backbone.view.extend({ template: jst['backbone/templates/tweetstemplate'], tagname: "section", id: 'tweets-container', initialize: function(){ this.listento(this.collection, 'reset', this.addall) }, render: function(){ this.$el.html(this.template()); return this; }, addone: function(tweet){ debugger var view = new tweetview({model: tweet}); view.render(); this.$el.find('#tweets-container').prepend(view.el); console.log("addone this: " + this); return this; }, addall: function(){ console.log('adding all') debugger //this.collection.length === 0 this.collection.each(function(tweet){ this.addone(tweet); }, this); return this; } })
i can include tweet model or view if needed- didn't seem relevant here i've been staring @ code few hours i'm biased.
i figured out. first off, yes, receiving valid json response success. problem was using rails-backbone gem, installs own backbone library custom backbone.sync method work more nicely rails. however, had put standard backbone.js in vendor/assets. suspect clobbering rails-backbone's own implementation. removed vendor backbone.js , well.
thanks all!
Comments
Post a Comment