2015-07-29 3 views
1

У меня есть коллекция, в которой я вставленный несколько документов, используя следующий код:Метеор приложение сбой при вызове метода

Projects.insert({ 
    source: "https://upload.wikimedia.org/wikipedia/commons/7/7f/Pug_portrait.jpg", 
    title: "Pug", 
    artist: "pug", 
    description: "This piece shows the duality of pug", 
    price: "$50" 
}); 

Projects.insert({ 
    source: "http://c.fastcompany.net/multisite_files/fastcompany/poster/2014/01/3025003-poster-p-dog-2.jpg", 
    title: "Dog", 
    artist: "dog", 
    description: "much doge, many deal with it, wow", 
    price: "$50" 
}) 

Projects.insert({ 
    source: "https://upload.wikimedia.org/wikipedia/commons/thumb/e/ea/Van_Gogh_-_Starry_Night_-_Google_Art_Project.jpg/1280px-Van_Gogh_-_Starry_Night_-_Google_Art_Project.jpg", 
    title: "Starry Night", 
    artist: "van gogh", 
    description: "night sky with stars", 
    price: "$75" 
}) 

Projects.insert({ 
    source: "http://totallyhistory.com/wp-content/uploads/2012/03/The_Scream.jpg", 
    title: "Scream", 
    artist: "edvard", 
    description: "scream", 
    price: "$50" 
}) 

Projects.insert({ 
    source: "https://www.petfinder.com/wp-content/uploads/2012/11/dog-how-to-select-your-new-best-friend-thinkstock99062463.jpg", 
    title: "Dog 2", 
    artist: "Bittu", 
    description: "This is a test to see how an actual thing would work", 
    price: "$50" 
}) 

Я создал следующий метод:

Meteor.methods({ 
    addProject: function (source, title, artist, description, price) { 
    // Make sure the user is logged in before inserting a task 
    if (! Meteor.userId()) { 
     throw new Meteor.Error("not-authorized"); 
    } 

    Projects.insert({ 
     source: source, 
     title: title, 
     artist: artist, 
     description: description, 
     price: price 
    }); 
    } 
}); 

При попытке позвонить метод, приложение выходит из строя и ссылается на следующую строку кода:

Meteor.call("addProject", "http://mybuzzblog.com/wp-content/uploads/2014/12/German-Shepherds.jpg", "Dog 3", "Me", "happy dog", "$60"); 

Вот что отображается консоль.

W20150729-12:26:31.609(-4)? (STDERR) 
W20150729-12:26:31.610(-4)? (STDERR) C:\Users\Raj\AppData\Local\.meteor\packages 
\meteor-tool\1.1.3\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\fiber 
s\future.js:245 
W20150729-12:26:31.610(-4)? (STDERR) 
throw(ex); 
W20150729-12:26:31.610(-4)? (STDERR) 
    ^
W20150729-12:26:31.610(-4)? (STDERR) Error: Method not found [404] 
W20150729-12:26:31.610(-4)? (STDERR)  at [object Object]._.extend.apply (pack 
ages/ddp/livedata_server.js:1502:1) 
W20150729-12:26:31.613(-4)? (STDERR)  at [object Object]._.extend.call (packa 
ges/ddp/livedata_server.js:1472:1) 
W20150729-12:26:31.613(-4)? (STDERR)  at app\art.js:5:8 
W20150729-12:26:31.613(-4)? (STDERR)  at app\art.js:137:3 
W20150729-12:26:31.613(-4)? (STDERR)  at C:\Users\Raj\art\.meteor\local\build 
\programs\server\boot.js:222:10 
W20150729-12:26:31.614(-4)? (STDERR)  at Array.forEach (native) 
W20150729-12:26:31.614(-4)? (STDERR)  at Function._.each._.forEach (C:\Users\ 
Raj\AppData\Local\.meteor\packages\meteor-tool\1.1.3\mt-os.windows.x86_32\dev_bu 
ndle\server-lib\node_modules\underscore\underscore.js:79:11) 
W20150729-12:26:31.614(-4)? (STDERR)  at C:\Users\Raj\art\.meteor\local\build 
\programs\server\boot.js:117:5 
=> Exited with code: 8 
=> Your application is crashing. Waiting for file change. 

Что мне делать, чтобы исправить это?

+1

Где вы определяете метод? – Kriegslustig

ответ

0

Убедитесь, что ваш Meteor.methods находится в папке сервера или в Meteor.isServer условно.