javascript - Meteor validated method not found - Stack Overflow

I'm migrating my Meteor application from Meteor 1.2 to Meteor 1.3 and following the guide on .html

I'm migrating my Meteor application from Meteor 1.2 to Meteor 1.3 and following the guide on .html#validated-method to create a validated method.

When I call the method, I believe client-side simulation is happening, as I can log out to console, but this is always followed by the error Method '...' not found.

/imports/ui/pages/register.js

import {Meteor} from 'meteor/meteor';
import {Template} from 'meteor/templating';
import {FlowRouter} from 'meteor/kadira:flow-router';

// Methods
import {createAccount} from '/imports/api/accounts/methods.js';

// HTML
import './register.html';

Template.Register_page.events({
  'submit form': function(event) {
    event.preventDefault();

    var user = {
      email: $('#email').val(),
      password: $('#password').val(),
      profile: {
        firstName: $('#firstName').val(),
        lastName: $('#lastName').val()
      }
    };

    createAccount.call(user, function(err) {
      if (err) {
        console.error(err);
      } else {
        console.log('User successfully registered');
        FlowRouter.go('Dashboard');
      }
    });
  }
});

/imports/api/accounts/methods.js

import {Meteor} from 'meteor/meteor';
import {ValidatedMethod} from 'meteor/mdg:validated-method';
import {SimpleSchema} from 'meteor/aldeed:simple-schema';
import {Accounts} from 'meteor/accounts-base';

export const createAccount = new ValidatedMethod({
  name: 'createAccount',
  validate: new SimpleSchema({
    email: { type: String },
    password: { type: String },
    profile: { type: Object },
    "profile.firstName": { type: String },
    "profile.lastName": { type: String }
  }).validator(),
  run(user) {
    console.log(user);
    Accounts.createUser(user);
  },
});

Client console

Object {email: "[email protected]", password: "testPassw0rd", profile: Object}    methods.js:18
errorClass {error: 404, reason: "Method 'createAccount' not found", details: undefined, message: "Method 'createAccount' not found [404]", errorType: "Meteor.Error"}    register.js:28

I'm migrating my Meteor application from Meteor 1.2 to Meteor 1.3 and following the guide on http://guide.meteor./methods.html#validated-method to create a validated method.

When I call the method, I believe client-side simulation is happening, as I can log out to console, but this is always followed by the error Method '...' not found.

/imports/ui/pages/register.js

import {Meteor} from 'meteor/meteor';
import {Template} from 'meteor/templating';
import {FlowRouter} from 'meteor/kadira:flow-router';

// Methods
import {createAccount} from '/imports/api/accounts/methods.js';

// HTML
import './register.html';

Template.Register_page.events({
  'submit form': function(event) {
    event.preventDefault();

    var user = {
      email: $('#email').val(),
      password: $('#password').val(),
      profile: {
        firstName: $('#firstName').val(),
        lastName: $('#lastName').val()
      }
    };

    createAccount.call(user, function(err) {
      if (err) {
        console.error(err);
      } else {
        console.log('User successfully registered');
        FlowRouter.go('Dashboard');
      }
    });
  }
});

/imports/api/accounts/methods.js

import {Meteor} from 'meteor/meteor';
import {ValidatedMethod} from 'meteor/mdg:validated-method';
import {SimpleSchema} from 'meteor/aldeed:simple-schema';
import {Accounts} from 'meteor/accounts-base';

export const createAccount = new ValidatedMethod({
  name: 'createAccount',
  validate: new SimpleSchema({
    email: { type: String },
    password: { type: String },
    profile: { type: Object },
    "profile.firstName": { type: String },
    "profile.lastName": { type: String }
  }).validator(),
  run(user) {
    console.log(user);
    Accounts.createUser(user);
  },
});

Client console

Object {email: "[email protected]", password: "testPassw0rd", profile: Object}    methods.js:18
errorClass {error: 404, reason: "Method 'createAccount' not found", details: undefined, message: "Method 'createAccount' not found [404]", errorType: "Meteor.Error"}    register.js:28
Share Improve this question asked Apr 15, 2016 at 8:41 Chris LivettChris Livett 2011 silver badge8 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 11

I believe the reason this wasn't working was because I was not initialising the javascript on the server at startup.

Adding the following fixed the issue:

/imports/startup/server/index.js

import './register-api.js';

/imports/startup/server/register-api.js

import '/imports/api/accounts/methods.js';

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744362271a4570529.html

相关推荐

  • javascript - Meteor validated method not found - Stack Overflow

    I'm migrating my Meteor application from Meteor 1.2 to Meteor 1.3 and following the guide on .html

    7天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信