【问题标题】:Meteor Autoform "Method '/insert' not found [404]"Meteor Autoform“找不到方法'/插入'[404]”
【发布时间】:2017-06-13 04:50:47
【问题描述】:

当我尝试提交表单时,autoform 包会抛出 404 错误。

我希望我得到了正确的安装说明和基本演示。 我尝试提供所需的文件。对于初学者来说,Schema、Html 和 JS 文件。

架构(imports/api/footballs/footballs.js):

import { Mongo } from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';


SimpleSchema.extendOptions(['autoform']);

export const Footballs = new Mongo.Collection('footballs');

Footballs.attachSchema (new SimpleSchema({
  playerone: {
    type: String,
    label: 'Player One',
    max: 255,
  },
  playertwo: {
    type: String,
    label: 'Player Two',
    max: 255,
  },
  gamedate: {
    type: Date,
    label: 'Game Data',
    autoValue: function autoValueCreatedAt() {
      return new Date();
    },
    autoform: {
      type: 'hidden'
    },
  },
},
{tracker: Tracker}));

HTML (imports/ui/pages/stadium.html)

<template name="stadium">
  <h1>Lets play kicker!</h1>
  {{> quickForm collection=footballCollection id="insertFootballsForm" type="insert" class="newFootballForm"}}
</template>

JS (imports/ui/pages/stadium.js)

import {Footballs} from '../../api/footballs/footballs.js';
import { Template } from 'meteor/templating';

import './stadium.html';

Template.stadium.helpers({
  footballCollection(){
    return Footballs;
  },
});

【问题讨论】:

  • 你是否也在服务器上定义了集合?
  • 我不太确定应该在哪里做。我认为 Js 文件(最后一个示例)将是集合的服务器端定义。
  • 您需要从服务器上的某个位置导入该集合。从您发布的代码中不清楚每段代码的确切位置以及从哪里导入。确保从服务器导入定义集合的文件(或特定于服务器的另一个集合定义文件)。
  • 添加了文件的路径。我试图坚持guide 我应该在启动文件夹中的某处注册集合吗?
  • 正如我之前多次提到的,检查文件是否已导入您的服务器。在浏览器控制台中打印内容并推断一切正常将导致我们无处可去。

标签: javascript meteor meteor-autoform


【解决方案1】:

感谢@MasterAM 的耐心,这是解决方案。该集合确实不存在于服务器端,因此必须导入。这没有发生。

服务器/main.js

import '../imports/startup/server';

(导入/启动/服务器/index.js)

import { Footballs } from '../../api/footballs/footballs.js';

【讨论】:

    【解决方案2】:

    您应该检查您是否使用了“不安全”模块,以及

    meteor list
    

    如果不在列表中,你可以

    meteor add insecure
    

    或者,在集合的定义之后添加它。

    Footballs.allow( { 
        insert() { 
            /*here goes the logic to determine if someone is allowed*/
            return true; 
        },
        update() { return true; },
        remove() { return true; }
    } )
    

    顺便说一句,如果你直接使用集合,你可以在模板上使用它而不是写一个帮助器:

    {{> quickForm collection="footballs" id="insertFootballsForm" type="insert" class="newFootballForm"}}
    

    【讨论】:

    • 添加insecure 通常是个坏主意,在这种情况下我认为不会解决问题。
    • 应用仍然[不安全],添加集合直接导致以下错误“模板助手中的异常:错误:足球不在窗口范围内”
    • Autoform 包不需要insecure 也不需要客户端上的允许/拒绝。
    猜你喜欢
    • 2017-10-11
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多