I’m learning Meteor by reading the Discover Meteor book and was able to implement posts
and comments
.
Now, I’m trying to add tags
same way posts
are implemented.
(Actually I’m going to experiment with many-to-many
relations, which is a different topic and I will make another post when I get there.)
I have 2 questions:
-
It’s not showing the following error when I click on Submit Tag button same way as for Submit Post.
> Access Denied You can't get here! Please log in.
-
It’s not showing up submit form when I click on Submit Tag
button after login.
Regarding the question #1, in routes.js
I have:
Router.onBeforeAction(requireLogin, {only: 'tagSubmit'});
Regaring the question #2, in routes.js
I have:
Router.route('/tags/submit', {name: 'tagSubmit'});
And my tag_submit.js
and tag_submit.html
as follows:
tag_submit.html
:
<template name="tagSubmit">
<form class="main form page">
<div class="form-group">
<label class="control-label" for="name">Name</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>
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.reason);
Router.go('tagPage', {_id: result._id});
});
}
});
Deployed at http://askar-blog.meteor.com/
Repo https://github.com/tenzan/blog/tree/tags (tags
branch)
Thanks!