Reputation: 11607
I'm following a tutorial on this site:
http://code.tutsplus.com/tutorials/working-with-data-in-sailsjs--net-31525
I'm stuck at the last part, leveraging web sockets.
Initially I typed the code but got the javascript error:
Uncaught TypeError: this.socket.request is not a function
So I decided to copy and paste the tutorial's code but it gave the same error.
This is the code block:
var SailsCollection = Backbone.Collection.extend({
sailsCollection: "",
socket: null,
sync: function(method, model, options){
var where = {};
if (options.where) {
where = {
where: options.where
}
}
if(typeof this.sailsCollection === "string" && this.sailsCollection !== "") {
this.socket = io.connect();
this.socket.on("connect", _.bind(function(){
this.socket.request("/" + this.sailsCollection, where, _.bind(function(users){
this.set(users);
}, this));
this.socket.on("message", _.bind(function(msg){
var m = msg.uri.split("/").pop();
if (m === "create") {
this.add(msg.data);
} else if (m === "update") {
this.get(msg.data.id).set(msg.data);
} else if (m === "destroy") {
this.remove(this.get(msg.data.id));
}
}, this));
}, this));
} else {
console.log("Error: Cannot retrieve models because property 'sailsCollection' not set on the collection");
}
}
});
I believe the tutorial might be outdated, but I am still hopeful I can fix this last bit, especially coming all this way.
Anyone know the proper way to use Sailsjs socket in this BackboneJS code ? (I know I'm searching for a needle in a haystack here).
Some initial discussion with the #Sailjs people on freenode IRC has brought to light the Grunt task are not running and so Socket.io is not being injected by Sails.js ?
OK seems like a duplicate question has already been asked here:
Sails is not injecting the files within the assets folder
Voting to close my own question, help me vote yes :)
Upvotes: 1
Views: 466
Reputation: 11607
The solution is to change the .sailsrc
in the project root, line:
{
"generators": {
"modules": {}
},
"hooks": {
"grunt": true
}
}
to
{
"generators": {
"modules": {}
},
"hooks": {
}
}
Upvotes: 1