2013-03-28 22 views
0

消除不安全的包後之後沒有其它數據,當我嘗試在服務器上執行插入它只是創造一個新的紀錄,只和_id流星只插入一個ID和消除不安全包

我已經允許插入在客戶端上的Customers.collection

Customers.allow({ 
    insert: function(userID) { 
     console.log(userID === userID); 
     return userID === userID; 
    } 
}); 

我打電話插入並通過它的用戶ID和表單數據

Template.tabs.events({ 
'submit form#customer' : function (event) { 

    console.log(event.type + event.currentTarget); 

    if (event.type === 'click' || event.type === 'submit') { 

     event.preventDefault(); 

     var name = $("#name").val(); 
     var address = $("#address").val(); 
     var city = $("#city").val(); 
     var state = $("#state").val(); 
     var zip = $("#zip").val(); 
     var phone = $("#phone").val(); 
     var fax = $("#fax").val(); 

     doc = {user_id: this.userID, name: name, address: address, city: city, state: state, zip: zip, phone: phone, fax: fax} 

     if(Customers.insert(this.userID, doc)) { 
      console.log("Inserted"); 
      $("#name").val(null); 
      $("#address").val(null); 
      $("#city").val(null); 
      $("#state").val(null); 
      $("#zip").val(null); 
      $("#phone").val(null); 
      $("#fax").val(null); 
     } 
    } 
} 
}); 

我也曾嘗試包插入在meteor方法中,並從客戶端進行方法調用,而不是使用相同的結果。

這裏是方法,並從客戶端

Meteor.methods({ 
    newCustomer: function (userID, record) { 
     Customers.insert(userID, record); 
        console.log("Inserted"); 
    } 
}); 

和客戶端,而不是INSERT語句即時通訊做如下的電話。

Meteor.call("newCustomer", this.userID, doc); 

我一直無法從流星文檔中找出任何其他解決方案,試圖使其發揮作用。

回答

2

的問題看起來是這一行:

if(Customers.insert(this.userID, doc)) { 

您插入應該是這樣的文件,正在插入的文件是參數

if(Customers.insert(doc)) { 

和允許功能需要檢查實際的文檔:

Customers.allow({ 
    insert: function(userID,doc) { 
     return userID === doc.user_id; 
    } 
}); 

而且更改文檔擁有者,this.userId旨在用於發佈在服務器上或Meteor.methods。爲了得到一個登錄用戶的用戶ID的其他地方使用Meteor.userId

doc = {user_id: Meteor.userId(), name: name, address: address, city: city, state: state, zip: zip, phone: phone, fax: fax} 
+0

對不起,這是我在問題中列出的代碼,但在我的代碼它同樣都是DOC一個錯字。我只是dbl檢查,它仍然不是問題。 謝謝。 – Moshe

+0

更新了答案希望它有幫助! – Akshat

+0

所以問題改變了,我只是不斷收到「插入失敗:訪問被拒絕」 – Moshe