Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
436 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...