Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 407
Alex C Avatar asked May 07 '12 13:05

Alex C


2 Answers

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");
like image 188
debergalis Avatar answered Nov 20 '22 15:11

debergalis


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
...
}
like image 36
Drag0 Avatar answered Nov 20 '22 15:11

Drag0