Tuesday, 15 February 2011

How to combine Meteor.publish/Subscirbe and collection.allow? -



How to combine Meteor.publish/Subscirbe and collection.allow? -

i tried write code understanding meteor.publish/subscribe , collection.allow it's don't have error can't insert info collection. testing.html

<head> <title>testing</title> </head> <body> <div class="container"> <div class="col-xs-2"> {{> loginbuttons}} </div> <div class="col-xs-10"> {{> gettingcontent}} </div> </div> </body> <template name="gettingcontent"> <h1>these contents.</h1> {{#each gettingall}} {{title}} {{author}} {{/each}} {{#if currentuser}} <h2 class="alert">{{denie}}</h2> <p>title: <input type="text" id="title"/></p> <p>author: <input type="text" id="author"/></p> <p><input type="button" value="click" id="action" /></p> {{/if}} </template>

model.js

content = new meteor.collection("content"); meteor.methods({ creatingcontent: function(options) { check(options, { title: string, author: string, date: new date() }); content.insert({ title: options.title, author: options.author, date: options.date }); } }); content.allow({ insert: function(userid) { if(meteor.userid() === true){ homecoming true; } else { homecoming false; } } });

clienttesting.js

template.gettingcontent.helpers({ gettingall : function(){ homecoming meteor.subscribe("getall"); } }); var options = { title: $("#title").val(), author: $("#author").val(), date: new date() }; template.gettingcontent.events({ 'click #action' : function(event,options) { event.preventdefault(); if(meteor.userid() === true) { meteor.call("creatingcontent",options); console.log("content created."); $("#title").val(""); $("#author").val(""); }else{ session.set("deny", "you must login creating content."); } } });

servertesting.js

meteor.publish('getall', function(){ if(content.find().count() === 0){ homecoming session.set("nodata", "data not found'"); } else { homecoming content.find({},{sort:{'date':-1}}); } });

i believe problem here: meteor.userid() === true

by default, meteor userid alphanumeric character string. testing equality true going false if userid exists.

try this:

if (meteor.userid()) { homecoming true; } else { homecoming false; }

or simpler:

return !!meteor.userid();

meteor

No comments:

Post a Comment