How to set up iron router to read my url

I have a books crud app that i have made and i need to view an individual item. My url looks like this

http://localhost:3000/crud/view/cwfet5RZxkZqog2s5

This is my code inside the CrudController

  view: function() {
   this.render('Viewed', {to: 'viewer'});
 },

This is my route

Router.route('/crud/view/:_id', {
  name: 'view',
  controller: 'CrudController',
  action: 'view',
  where: 'client'
});

and this is my helper

Template.Viewed.helpers({
  'crud/view/:id': function(){
 return Crud.findOne({_id: this.params._id});
    }
});

My code as is gives me a blank when i try to access the db value in the template like{{name}}

Can someone guide me on how to set up my code when i have the url am having.

Your helper looks weird. Can you show your template code?

This is my Viewed template

<template name="Viewed">

   {{name}}

   lorem ipsum
</template>

So the helper should be name, unless you call your template with data. Bottom line is that you are mixing the syntax/concept for your URL as defined with Iron Router with how helpers work. Two completely different things.

I recommend to check out the meteor guide

The guide is using flowrouter and that will take me hours to look at at especially blaze and the templating.

It would really be helpful for me to know at what point i should be passing data from db to the view. Is it on the helper or on the controller.

Thats the thing confusing me.

For iron router, I think this is it:

Template.Viewed.helpers({
  'crudItem': function(){
     return Crud.findOne({_id: Router.current().params._id});
  }
});

and then

<template name="Viewed">
  {{crudItem.name}}
</template>
1 Like

Thanks. That solved it,

1 Like