Saving user ID in Meteor when using AutoForm

Sat Jul 05 2014

How to store the logged in users ID when submitting a quickform.

First of all, you have to add the users ID to you collection schema. As you don't want the user to fill in this value, you must set it's value with autoValue.

@Books = new Meteor.Collection "books",
      type: String
      label: "Name"
      type: String
      autoValue: ->

If you now use the default quickForm helper, a field for user will be generated, even though we give it an automatic value. So solve this, use the omitFields parameter.

{{> autoForm collection="Books" id="insertBookForm" type="insert" omitFields="user"}}

A form will now be generated for the schema defined in your collection, without the user field. The user field will upon saving be filled with the currently logged in users ID.