简体   繁体   中英

Meteor Autoform “Method '/insert' not found [404]”

I've got this strange behavior that the autoform package throws a 404 when i try to submit my form.

I hope i got the install instructions and the basic demo right. I try to provide the needed files. For starters the Schema, Html and the JS File.

Schema (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;
  },
});

Thanks to @MasterAM patience, here is the solution. The collection was indeed not present on the server side and therefore had to be imported. Which didn't happend.

Server/main.js

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

(imports/startup/server/index.js)

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

You should check if you're using the 'insecure' module, with

meteor list

if it's not on the list, you can

meteor add insecure

or, add this after the definition of the collection.

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

btw, if you're using the collection directly, you could use this on the template instead of writing a helper:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM