Meteor Iron:Router Template not Rendering -
i have main page lists few text items ("ideas"), clickable links. clicking on them should take page can edit them. here's html:
<head> <title>ideas</title> </head> <body> </body> <template name="ideas"> <ul> {{#each ideas}} {{> idea}} {{/each}} </ul> </template> <template name="idea"> <li><a href="/idea/{{_id}}">{{text}}</a></li> </template> <template name="showidea">' <div class="editable" contenteditable="true">{{text}}</div> </template>
i've added iron:router
project allow moving between pages. here's javascript:
ideas = new mongo.collection("ideas"); if (meteor.isclient) { router.route('/', function() { this.render('ideas'); }); router.route('/idea/:_id', function() { var idea = ideas.findone({_id: this.params._id}); this.render('showidea', {text: idea.text}); }); template.ideas.helpers({ ideas: function () { return ideas.find({}); } }); }
i inserted single idea mongo db using meteor mongo command line tool. single item shows on main page. here's html looks in debugger main page:
<html> <head>...</head> <body> <ul> <li> <a href="/idea/objectid("550b7da0a68cb03381840feb")">the first idea ever</a> </li> </ul> </body> </html>
clicking on link takes me new page address of:
http://localhost:3000/idea/objectid(%22550b7da0a68cb03381840feb%22)
but nothing shows on page. in debugger console see error message + stack trace, means nothing me since seems pertaining iron-router , meteor, not code wrote:
exception in callback of async function: http://localhost:3000/idea.js?2fd83048a1b04d74305beae2ff40f2ea7741d40d:10:44 boundnext@http://localhost:3000/packages/iron_middleware-stack.js?0e0f6983a838a6516556b08e62894f89720e2c44:424:35 http://localhost:3000/packages/meteor.js?e53378596562e8922a6369c955bab1e047fa866b:978:27 onrerun@http://localhost:3000/packages/iron_router.js?a427868585af16bb88b7c9996b2449aebb8dbf51:520:13 boundnext@http://localhost:3000/packages/iron_middleware-stack.js?0e0f6983a838a6516556b08e62894f89720e2c44:424:35 http://localhost:3000/packages/meteor.js?e53378596562e8922a6369c955bab1e047fa866b:978:27 onrun@http://localhost:3000/packages/iron_router.js?a427868585af16bb88b7c9996b2449aebb8dbf51:505:15 boundnext@http://localhost:3000/packages/iron_middleware-stack.js?0e0f6983a838a6516556b08e62894f89720e2c44:424:35 http://localhost:3000/packages/meteor.js?e53378596562e8922a6369c955bab1e047fa866b:978:27 dispatch@http://localhost:3000/packages/iron_middleware-stack.js?0e0f6983a838a6516556b08e62894f89720e2c44:448:7 _runroute@http://localhost:3000/packages/iron_router.js?a427868585af16bb88b7c9996b2449aebb8dbf51:543:17 dispatch@http://localhost:3000/packages/iron_router.js?a427868585af16bb88b7c9996b2449aebb8dbf51:844:27 route@http://localhost:3000/packages/iron_router.js?a427868585af16bb88b7c9996b2449aebb8dbf51:710:19 boundnext@http://localhost:3000/packages/iron_middleware-stack.js?0e0f6983a838a6516556b08e62894f89720e2c44:424:35 http://localhost:3000/packages/meteor.js?e53378596562e8922a6369c955bab1e047fa866b:978:27 boundnext@http://localhost:3000/packages/iron_middleware-stack.js?0e0f6983a838a6516556b08e62894f89720e2c44:371:18 http://localhost:3000/packages/meteor.js?e53378596562e8922a6369c955bab1e047fa866b:978:27 dispatch@http://localhost:3000/packages/iron_middleware-stack.js?0e0f6983a838a6516556b08e62894f89720e2c44:448:7 http://localhost:3000/packages/iron_router.js?a427868585af16bb88b7c9996b2449aebb8dbf51:390:21 _compute@http://localhost:3000/packages/tracker.js?21f0f4306879f57e10ad3a97efe9ea521c5b5775:308:36 computation@http://localhost:3000/packages/tracker.js?21f0f4306879f57e10ad3a97efe9ea521c5b5775:224:18 autorun@http://localhost:3000/packages/tracker.js?21f0f4306879f57e10ad3a97efe9ea521c5b5775:499:34 http://localhost:3000/packages/iron_router.js?a427868585af16bb88b7c9996b2449aebb8dbf51:388:17 nonreactive@http://localhost:3000/packages/tracker.js?21f0f4306879f57e10ad3a97efe9ea521c5b5775:525:13 dispatch@http://localhost:3000/packages/iron_router.js?a427868585af16bb88b7c9996b2449aebb8dbf51:387:19 dispatch@http://localhost:3000/packages/iron_router.js?a427868585af16bb88b7c9996b2449aebb8dbf51:1688:22 onlocationchange@http://localhost:3000/packages/iron_router.js?a427868585af16bb88b7c9996b2449aebb8dbf51:1772:33 _compute@http://localhost:3000/packages/tracker.js?21f0f4306879f57e10ad3a97efe9ea521c5b5775:308:36 _recompute@http://localhost:3000/packages/tracker.js?21f0f4306879f57e10ad3a97efe9ea521c5b5775:322:22 flush@http://localhost:3000/packages/tracker.js?21f0f4306879f57e10ad3a97efe9ea521c5b5775:452:24
and ends warning message:
route dispatch never rendered. did forget call this.next() in onbeforeaction?
i don't have onbeforeaction
(i'm not sure is)... don't think message pertains me?
i started using meteor other day , added iron-router not 24 hours ago, i'm bit lost here. pointers on how can debug , fix great.
two things need fixing:
- when insert documents shell assigned
_id
values mongoobjectid
s, whereas meteor defaults using strings. explains weird url. avoid problem, it's best initialize data server. here's example:
if (meteor.isserver) { meteor.startup(function() { if (ideas.find().count() === 0) { ideas.insert({text: 'feed cat'}); } }); }
now after $ meteor reset
start 1 cat-related idea.
- if wish pass context template, you'll need use
data
attribute so:
router.route('/idea/:_id', function() { this.render('showidea', { data: function () {return ideas.findone({_id: this.params._id})} }); });
see this example docs. after making changes, code worked correctly me.
Comments
Post a Comment