控制器无法识别Ember Validations mixin

时间:2016-06-27 13:45:23

标签: ember.js emberfire ember-validations

我正在使用ember-validations和EmberFire创建一个注册表单。我的服务器启动正常,但我的控制台显示此错误:

Uncaught Error: Could not find module `app/mixins/validations/signup` imported from `processapp/controllers/signup`

以下是我的注册验证mixin的代码:

import Ember from 'ember';
import EmberValidations from 'ember-validations';

export default Ember.Mixin.create(EmberValidations, {
  validations: {
    "model.firstName": {
      presence: true
    },
    "model.lastName": {
      presence: true
    },
    "model.email": {
        format: { with: /^.+@.+\..+$/, message: 'Please enter a valid email address.' }
    },
    "model.password": {
        length: {minimum: 6, maximum: 30},
        presence: true,
        confirmation: true
    }
  },
});

以下是我的注册控制器的代码:

import Ember from 'ember';
import SignupValidations from 'app/mixins/validations/signup';

export default Ember.Controller.extend(SignupValidations, {
actions: {
    createUser(){
      //...
      this.validate().then(()=>{
        var newUser = this.store.createRecord('user', {
            firstName: this.get('firstName'),
            lastName: this.get('lastName'),
            email: this.get('email'),
            password: this.get('password')
        });
        newUser.save().then(()=>{
          this.transitionToRoute('user', newUser);
        });
      }).catch(()=>{
        console.log(this.get("errors"));
      });
    }
  }
});

文件结构似乎与我的控制器中导入SignupValidations行中包含的结构相匹配,所以我有点困惑为什么我收到此错误。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

我找到了答案。我不得不使用app作为我想要使用的文件结构的顶部,而是必须使用一个文件夹并使用processapp作为文件结构的顶部。

而不是app/mixins/validations/signup

必须是processapp/mixins/validations/signup