Skip to content

Instantly share code, notes, and snippets.

@drew-gross
Created August 10, 2013 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drew-gross/6202629 to your computer and use it in GitHub Desktop.
Save drew-gross/6202629 to your computer and use it in GitHub Desktop.
Buggy Meteor App
/* CSS declarations go here */
<head>
<title>DrinkTabThing</title>
</head>
<body>
{{renderPage}}
</body>
<template name="tab">
<h1>Menu</h1>
{{#each drinks_menu}}
{{> drink_from_menu}}
{{/each}}
<hr>
<h1>My Tab</h1>
{{#each ordered_drinks}}
{{> drink_from_tab}}
{{/each}}
</template>
<template name="drink_from_menu">
<div>{{name}}: ${{price}}<input type="button" value="buy one" class="buy_drink"/></div>
</template>
<template name="drink_from_tab">
<div>{{name}}: ${{price}}</div>
</template>
Tabs = new Meteor.Collection('tabs');
Drinks = new Meteor.Collection('drinks');
if (Meteor.isClient) {
Meteor.Router.add({
'/': 'home',
'/tabs/:id': function (id) {
Session.set('tabId', id);
return 'tab';
}
});
Template.tab.drinks_menu = function(){
return Drinks.find({});
};
Template.tab.ordered_drinks = function () {
return Tabs.findOne(Session.get('tabId')).ordered_drinks;
};
Template.drink_from_menu.events({
'click .buy_drink': function () {
Tabs.update({_id:Session.get('tabId')}, {$push: {ordered_drinks: this}});
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
Meteor.Router.add({
'/tabs/:id.xml': function(id) {
return Tabs.findOne(id).owner;
}
});
if (Drinks.find().count() === 0) {
Drinks.insert({name: "Screwdriver", price: "5.00"});
Drinks.insert({name: "Rum and Coke", price: "5.50"});
Drinks.insert({name: "Kilkenny's", price: "8.00"});
}
});
}
@alanning
Copy link

I put together a fixed version of this here: https://github.com/alanning/meteor-buggy-fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment