SOLVED: A document is not saved


#1

Deployed at http://askar-blog.meteor.com/
Repo https://github.com/tenzan/blog

When I submit a tag, it’s not being saved.

Posts are created w/o any problem.

Related parts as follows.

tags.js:

Tags = new Mongo.Collection('tags');

Meteor.methods({
    tagInsert: function (tagAttributes) {
        check(Meteor.userId(), String);
        check(tagAttributes, {
            title: String
        });
        var user = Meteor.user();
        var tag = _.extend(tagAttributes, {
            userId: user._id,
            author: user.username,
            submitted: new Date()
        });
        var tagId = Tags.insert(tag);
        return {
            _id: tagId
        };
    }
});

server/publications.js:

Meteor.publish('tags', function () {
    return Tags.find();
});

tag_submit.js:

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

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

        Meteor.call('tagInsert', tag, function (error, result) {
            //display the error to the user and abort
            if (error)
                return alert(error.message);
            Router.go('tagPage', {_id: result._id});
        });
    }
});

tag_submit.html:

<template name="tagSubmit">
    <form class="main form page">
        <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 tag" class="form-control">
            </div>
        </div>
        <input type="submit" value="Submit" class="btn btn-primary">
    </form>
</template>

#2

I don’t see anything wrong. No server-side error when inserting? Is the tag inserted on server? (you can check that with console.log(Tags.find().fetch()) somewhere on server).


#3

Where would I run the command above?

I checked that nothing is saved in the meteor mongo shell.


#4

‘submit form’

typos rulezz


#5

Thanks a lot! :smile: