javascripthtmlmeteormeteor-blazemeteor-autoform

Meteor quickForm Exception in template helper: Error: Recipes is not in the window scope


I am unable to get the app working on Meteor. quickform is not linking my Collection.

"Exception in template helper: Error: Recipes is not in the window scope"

Anyone can help out here?

Here is my quickform code

<template name="NewRecipe">
	<div class="new-recipe-container">
		{{> quickForm collection="Recipes" id="insertRecipeForm" type="insert" class="new-recipe-form" }}
		
	</div>
</template>

and here is my collection schema

Recipes = new Mongo.Collection('recipes');

RecipeSchema = new SimpleSchema({
	name: {
		type: String,
		label:"Name"
	},
	desc: {
		type: String,
		label:"Description"
	},
	author: {
		type: String,
		label:"Author",
		autoValue: function() {
			return this.userId
		}
	},
	createdAt: {
		type: Date,
		label:"Created At",
		autoValue: function() {
			return new Date()
		}
	}

});

Recipes.attachSchema( RecipeSchema );


Solution

  • I'm not able to comment on your question because I've less than 50 reputations, so I'm posting this as an answer.

    I'm following the same intermediate meteor Level Up Tuts, but by trying to follow the new Application structure and import syntax because I'm using Meter 1.3 and I wanted to follow along the latest best practices.

    I had this error because when I was trying to write

    {{> quickForm collection="Recipes" id="insertRecipeForm" type="insert" class="new-recipe-form" }}
    

    i.e.

    collection="Recipes" (with quotations)

    This was a problem because in Meteor 1.3, because there are no "global" things in Meteor 1.3 anymore thanks to the es2015 modules. I wasn't defining Collection like you did (and like Scott in the Level Up Tuts has), I was defining the Collection with a const declaration and exporting it with ec2015 modules syntax (see the github issue I've provided). Point being my Collection wasn't in Global Scope. So instead I had to write a template helper to return the collection and write the quickForm template inclusion like this :

    collection=Recipes (without quotations)

    Now Recipes here is a template helper which returns the Recipes Collection Object

    Template.NewRecipe.helpers({
      Recipes(){
        return Recipes;
      }
    });
    

    I got to know about this issue from here

    But since you are using the older application structure approach of Meteor (I suppose?) which Meteor is still supporting, there could be only one problem that I can think of right now, that newest version of autoform was designed specifically for Meteor 1.3 in mind. I searched Meteor forums and I got one post that had a same concern.

    You can try two things :

    1. Try what he did to fix these global errors, i.e. explicitly add the collection to the window object.
    2. Try reverting back to an older version of autoform like he did.

    And perhaps let me know the findings for each?