[SOLVED] Editing doc using Iron:Router and AutoForm

I have Iron:Router setup with the following route:
Router.route('/building/update/:_id', { name: 'building_edit', template: 'building_edit', data: function() { return Buildings.findOne(this._id); } });

and my building_edit template has the following code
{{#autoForm schema=Schemas.Buildings type="update" id="update_building" doc=this }} ... {{> afQuickField name="name" }} ... {{/autoForm}}

When I go to http://localhost:3000/building/update/YXs2C5mnv7rqaqQ7B
the form shows up but none of the fields have the Building’s data.

Any ideas what I’m missing?

Is there something that I left out of this post that you may need to know? I’m really stuck as to why this doesn’t work.

Assuming you have autopublish disabled, where are you subscribing to your Buildings collection?

Autopublish is indeed disabled.

In server/publish.js
Meteor.startup(function () {
Meteor.publish(ā€œbuildingsā€, function() {
return Buildings.find();
});
…
});

In /my_app.js (this is the file that was created when I ā€˜meteor create my_app’)
if (Meteor.isClient) {
Meteor.subscribe(ā€œbuildingsā€);
}

A few suggestions:

  1. Meteor.publish doesn’t need to be part of a startup callback, so I’d suggest removing it from Meteor.startup.
  2. Take a look at the subscriptions section of the Iron Router Guide. You’ll likely want to leverage the subscriptions or waitOn Iron Router options.
  3. Are you very far down the path of using Iron Router? If not I’d suggest switching to use kadira:flow-router (since it’s currently the MDG recommended router) along with template level subscriptions.
1 Like

I took the .publish calls out of the startup. It had no effect, but I will leave it like that on your suggestion.

I implemented the subscriptions and waitOn options to my routes, and it started working. Thank you.