Many resources on the internet (including here) suggest using
Specifically, it seems like file order dependency is the reason I can't get my posts.coffee collection to recognize permissions defined in my permissions.coffee. I think this is happening because posts.coffee is in /lib/collections, whereas permissions.coffee is in /lib, and files in subdirectories get loaded first. (Incidentally, I would prefer /collections to be in the root directory, but I had to move it into /lib previously to solve a similar problem.)
Here is my posts.coffee:
@Posts = new Meteor.Collection('posts')
@ownsDocument = (userId, doc)->
doc && doc.userId == userId
Yes, you do just that:
Meteor.startup -> Posts.allow( ... )
Basically, any piece of code that uses a variable defined in another file should be preceded by
Meteor.startup ->, unless you are sure that the loading order is correct (the variable is in lib, for example).
Yes, the loading order is poorly chosen.