mtwallet
mtwallet

Reputation: 5086

Meteor.call method not found

I am working my way through the Microscope project in Discover Meteor and I have hit a problem. I am getting a 'Method not found' error for the following code:

HTML Template - microscope/client/templates/posts/post_submit.html

<template name="postSubmit">
<form class="main form">

    <div class="form-group">
        <label class="control-label" for="url">URL</label>
        <div class="controls">
            <input name="url" id="url" type="text" value="" placeholder="Your URL" class="form-control"/>
        </div>
    </div>

    <div class="form-group">
        <label class="control-label" for="title">Title</label>
        <div class="controls">
            <input name="title" id="title" type="text" value="" placeholder="Name your post" class="form-control"/>
        </div>
    </div>

    <input type="submit" value="Submit" class="btn btn-primary"/>

</form>

JS - microscope/client/templates/posts/post_submit.js

Template.postSubmit.events({
    'submit form': function(e) {
    e.preventDefault();

    var post = {
       url: $(e.target).find('[name=url]').val(),
       title: $(e.target).find('[name=title]').val()
    };

    Meteor.call('postInsert', post, function(error, result) {
        // display the error to the user and abort
        if (error)
            return alert(error.reason);
            Router.go('postPage', {_id: result._id});  
        });
    }
});

I am not sure how to debug this as I am getting no errors in the console. Please can anyone suggest where I am going wrong?

Upvotes: 1

Views: 607

Answers (1)

Mark Dawson
Mark Dawson

Reputation: 33

Very likely that you need to add the method postInsert to the server side. If you're following along in Discover Meteor, they do that in the next section - https://book.discovermeteor.com/chapter/creating-posts

For example, you put the method in a file called lib/collections/posts.js like this

Meteor.methods({
  postInsert: function(postAttributes) {
    check(Meteor.userId(), String);
    check(postAttributes, {
      title: String,
      url: String
    });

Upvotes: 2

Related Questions