Drug = new Mongo.Collection('drugData');
if(Meteor.isClient)
{
Template.drugs.events(
{
'submit .new-drug':function(event)
{
event.preventDefault();
var name = event.target.name.value;
var type = event.target.type.value;
var rating = Number(event.target.Rating.value);
Meteor.call('addDrug',name,type,rating);
event.target.name.value="";
event.target.type.value="";
event.target.Rating.value="";
}
});
Template.drugs.helpers(
{
'druglist':function()
{
return Drug.find({},{sort:{createdAt:-1}});
}
}
);
}
if(Meteor.isServer)
{
Meteor.publish('druglist',function()
{
return Drug.find();
});
}
Meteor.methods(
{
addDrug:function(name,type,rating)
{
Drug.insert(
{
name:name,
type:type,
rating:rating,
createdAt:new Date()
});
}
}
);
//////my router///////
Router.configure({
layoutTemplate:'layout'
});
Router.map(function()
{
this.route('login',{path:'/'});
this.route('claims',{path:'/claims'});
this.route('clients',{path:'/clients'});
this.route('employees',{path:'/employees'});
});
Router.route('/drugs',
{
name:'drugs',
template:'drugs',
data: function()
{
Meteor.subscribe('druglist');
}
});
I'm new to meteor and i am currently learning routing, i am having a problem displaying my data when using routing with publish and subscribe. When i run the code with autopublish and insecure and don't use publish and subscribe my data shows on my pages, but when i remove autopublish and insecure and use publish and subscribe i get the error 'method "addDrug" not found:404'.
This is my template code
<template name="drugs">
<h3>this is the drugs page</h3>
<form class= "new-drug">
<input name="name" type="text" placeholder="Drug name">
<input name="type" type="text" placeholder="Drug Classification">
<input name="Rating" type="text" placeholder="Drug Rating">
<button type="submit">Add Drug<span class="fa fa-plus"></span></button>
</form>
<div>
<ol>
{{#each druglist}}
<li>{{name}}--{{type}}--{{rating}}</li>
{{/each}}
</ol>
</div>
</template>