Skip to content

Instantly share code, notes, and snippets.

@AlexFrazer
Created February 24, 2015 15:12
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 AlexFrazer/aea58f72876b4f951a31 to your computer and use it in GitHub Desktop.
Save AlexFrazer/aea58f72876b4f951a31 to your computer and use it in GitHub Desktop.
quick bug in my code using meteor
Template.imageboard.helpers({
posts: function() {
return Posts.find({}, { sort: { timestamp: -1} });
},
has_posts: function() {
return Posts.find({}).count() > 0;
}
});
Template.write.events({
'submit #form': function(event) {
var title = event.target.title.value;
var content = event.target.content.value;
console.log(title);
console.log(content);
Posts.insert({
title: title,
content: content,
timestamp: new Date()
});
event.target.title.value = "";
event.target.content.value = "";
return false;
}
});
<head>
<title>Imageboard</title>
<meta name="viewport" content="width=device-width, user-scalable=no">
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="outer">
<div class="logo"></div>
{{> imageboard}}
</div>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script type="text/javascript" src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
</body>
<template name="imageboard">
<div class="container-fluid">
<div class="page-lead text-center">
<h1>Forum</h1>
</div>
{{> write}}
<hr/>
{{#if has_posts}}
{{#each posts}}
{{> post}}
{{/each}}
{{else}}
<div class="text-center">
<p class="text-muted lead">There are current no posts</p>
</div>
{{/if}}
</div>
</template>
<template name="post">
<div class="row">
<div class="col-md-4">
<h3>{{ title }}</h3>
<p>{{ content }}</p>
</div>
</div>
</template>
<template name="write">
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6">
<form role="form" class="form-horizontal" id="form">
<div class="form-group">
<input type="text" class="form-control" name="title" id="title" placeholder="title"/>
</div>
<div class="form-group">
<textarea class="form-control" rows="5" name="content" id="content" placeholder="content"></textarea>
</div>
<div class="form-group">
</div>
</form>
<button type="submit" class="btn btn-large btn-primary btn-block">Publish</button>
</div>
<div class="col-md-3"></div>
</div>
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment