The problem is unlike other pages in the website, I can’t give any kind of form on this page to take user input and store that input in the database.
I am adding the dishes specifications like name, price etc. directly in the collection through the command line but the problem is when I’m trying to iterate these dishes on to my order online page through a helper function, I’m getting an exception in template helper: order_online error at the console. Please help how can resolve this problem?
import { Mongo } from ‘meteor/mongo’;
export const Order_online = new Mongo.Collection(‘order_online’);
This is my collection.
import { Meteor } from ‘meteor/meteor’;
import { Order_online } from ‘…/order_online.js’;
Meteor.publish(‘order_online.all’, function(){
return Order_online.find();
});
This is my publication.
import “./order-online.html”;
import “…/…/components/navbar/main_navbar.js”;
import “./order-online.css”;
import “…/…/components/footer/footer.js”;
Template.order_online.onRendered(function(){
this.subscribe(“order_online.all”);
});
Template.order_online.helpers({
order_online: function(){
return Order_online.find();
}
});
This is my helper and subscription.
{{#each order_online}}
<h3>{{name}}</h3>
<p>{{desc}}</p>
<button class="crt">Add To Cart</button>
{{/each}}
This is how I’m trying to iterate the values inserted into the collection through a query in command line as follows:
meteor:PRIMARY> db.order_online.insert({name: “tuna3”, desc: “sweet3”, price: “59”});
I’m expecting tuna3, sweet3 and 59 to be shown on the order_online page as a result of all of the above code but it’s giving me exception in template helper : order_online error at the console.
Please edit your post and ensure each code block is wrapped in triple-backticks, like this:
```
your
code
here
```
to make it easier to read.
I’m doing this at the mongo shell to insert data into my collection: db.orderonline.insert({dishname: “Sushi”, dishprice: “99”})
Now I want to iterate these values in my template and I am doing so using a helper as {{dishname}} and {{dishprice}}. I expect Sushi and 99 to be shown on my webpage. But it’s just not happening and I’m getting exception in my template helper: orderonline error.
I’ve thought about this a lot and I don’t understand why my helper is not throwing the information to my DOM from the collection.
Somehow I have managed to get everything in place and everything is working fine. I have a cart template embedded in my order_online template. Now the dish that I have rendered (iterated) from the database(collection) on to my order_online template through a helper, I have given an add button below the dish. Please tell me what method should I write so that when I click on the add button, the dish gets rendered into the cart template. I know I need to write publication and subscription for the cart template as well but by going this way the dishes will get rendered to the cart automatically, I want them rendered only when I click on add. Please help!
The easiest way is probably to call a Meteor method when the button’s clicked.
The method would then insert the appropriate reference into the “cart collection”.