[Iron-Router] Simple "Did I do this correctly?" and "How does it work?" post

Last night after hacking away on a Meteor project, with Iron-CLI - I FINALLY understood how to render dynamic content with Blaze via URLs. I’ve been tinkering with Meteor for quite some time now and it feels damn good, just want to be sure I’m following “best practices” or what is common.

So here’s how I did my www.site.com/items :

  1. I registered the collection and added some documents
  2. I created this route:
Router.route('items', {
  name: 'items',
  controller: 'ItemsController',
  where: 'client'
});

3 . I put this in my items.js (helper)

Template.Items.helpers({
  items() {
  return Items.find({});
}
});

4 . I then iterate through the documents in the collection:

<template name="Item">
  {{#each items}}
                <td>{{title}}</td>
                {{#linkTo route='item'}}
  {{/each}}
...etc

Is this right? Should the return Items.find({}); be in the router instead of a helper for best practices? If so, how (I couldn’t get it working)?

And this is how I did my www.site.com/items/:_id

  1. I registered the collection and added some documents
  2. I registered the route (had to do it differently):
Router.route('/items/:_id', {
  name: 'item',
  controller: 'ItemsController',
  where: 'client',
  data: function(){
      var itemList = this.params._id;
      //console.log(itemList)
      return Items.findOne({ _id: itemsList });
  }
});

3 . The return.Items.findOne({ _id: itemsList }); didn’t work in the item.js helpers file for whatever reason
4. And finally my template:

<template name="Item">
       <td>{{title}}</td>
...etc

Why doesn’t adding the findOne to the template helper work? Is the helper not aware of the current route and this has to come from the router? Is it recommended that I used the came controller file for /items/ and /items/:_id?

Thanks all :slight_smile: I’m loving Meteor so far. All it took was a day of trial and error and not giving up and it seemed to finally click after being interested in Meteor for the last few years. Funnily enough, it took me starting to learn Ruby on Rails to figure it out and Iron-CLI for some project structure.

Best practices for Meteor would be not to do your subscriptions and queries in the router. This means, not the Iron Router way. But there are still Iron Router users who feel comfortable with it.