我正在创建我的第一个流星项目。我试图使用autoform将数据插入集合。我注意到集合似乎没有发布,当我尝试提交表单时出现此错误。
errorClass {error: 404, reason: "Method '/recipes/insert' not found", details: undefined, message: "Method '/recipes/insert' not found [404]", errorType: "Meteor.Error"}
我正在尝试遵循推荐的应用程序结构。
进口/ API /列表/ recipes.js
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
export const Recipes = new Mongo.Collection('recipes');
Recipes.allow({
insert: function (userId, doc) {
// the user must be logged in, and the document must be owned by the user
return (userId && doc.owner === userId);
},
update: function (userId, doc, fields, modifier) {
// can only change your own documents
return doc.owner === userId;
},
remove: function (userId, doc) {
// can only remove your own documents
return doc.owner === userId;
},
fetch: ['owner']
});
RecipeSchema = new SimpleSchema({
name: {
type: String,
label: "Name",
},
desc: {
type: String,
label: "Description"
},
author: {
type: String,
label: "Author",
autoValue: function() {
return this.userId
},
autoform: {
type: "hidden"
}
},
createdAt: {
type: Date,
label: "Created At",
autoValue: function() {
return new Date()
},
autoform: {
type: "hidden"
}
}
});
Recipes.attachSchema( RecipeSchema );
进口/ API /列表/服务器/ publish.js
import { Meteor } from 'meteor/meteor';
import { Recipes } from '../recipes.js';
if (Meteor.isServer) {
// This code only runs on the server
Meteor.publish('recipes', function(){
console.log('Published')
return recipes.find({author: this.userId});
});
}else{
console.log("Not server");
}
服务器/ main.js
import { Meteor } from 'meteor/meteor';
import '../imports/api/lists/server/publish.js';
Meteor.startup(() => {
// code to run on server at startup
});
进口/ UI /布局/食谱/ newRecipe.js
import { Template } from 'meteor/templating';
import { Recipes } from '../../../api/lists/recipes.js';
import './newRecipe.html'
Template.NewRecipe.helpers({
formCollection() {
return Recipes;
}
});
进口/ UI /布局/食谱/ newRecipe.html
<template name="NewRecipe">
<div id="new-recipe-container">
{{> quickForm collection=formCollection id="insertRecipeForm" type="insert" class="new-recipe-form"}}
</div>
</template>
如果有人能帮助我,请告诉我哪里出错我会很棒。 谢谢