Meteor using a local connection results in error: insert failed: 404 — Method not found

隐身守侯 提交于 2019-11-30 07:16:29

问题


I've got a meteor collection on the client side

Friends = new Meteor.Collection("Friends");
Meteor.subscribe("Friends");

I have a user authenticate with facebook and I want to grab a list of their friends:

FB.api("/me/friends?    auth_token="+response.authResponse.accessToken,
    function(response){
        for (i = 0; i<response.data.length;i++){
            Friends.insert(response.data[i]);
    }
);

I have a function to get that list:

Template.Friends.all_friends = function(){
    return Friends.find();
} 

I have a template that would like to display all the friends on the screen:

<template name="Friends">
    {{#each all_friends}}
    <div id="{{id}}" class="friend">
        <img src="http://graph.facebook.com/{{id}}/picture" />
        {{name}}
    </div>
    {{/each}}
</template>

What appears to be happening on the page is that all the friends DO flash up on the screen for a split second then immediately the screen flashes back to blank.

In the javascript console the message appears once per friend I have (yes, it is more than zero, thanks for asking)

insert failed: 404 -- Method not found

So! What have I missed? Anyone?


回答1:


You need that Collection declaration on both the client and the server.

// common code, do not put under /client or inside Meteor.is_client test
Friends = new Meteor.Collection("Friends");



回答2:


If you want to use Collection only on Client side and you don't need to save that data to server you can declare your collection in "client" folder or in .isClient() function by passing null to the constructor like this:

if(Meteor.isClient()){
// Some other code
...

onlyClientCollection = new Meteor.Collection(null);

// Some other code
...
}


来源:https://stackoverflow.com/questions/10483142/meteor-using-a-local-connection-results-in-error-insert-failed-404-method-n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!