1
我在嘗試創建一個用戶,當出現以下錯誤:當改性劑的選擇是正確,驗證對象必須有至少一個運營商 - 系列2包 - 流星
Exception while invoking method 'createUser' Error: When the modifier option
is true, validation object must have at least one operator
這裏是我正在呼叫的createUser
方法:
Template.register.events({
"submit #register_form": function(event) {
event.preventDefault();
var $form = $("#register_form");
var attr = {};
var profile = {};
// We gather form values, selecting all named inputs
$("input[name]", $form).each(function(idx) {
var $input = $(this);
var name = $input.attr("name");
if (name == "email" || name == "password") {
attr[ name ] = $input.val();
}
else if (name != "repeat_password") {
profile[ name ] = $input.val();
}
});
attr.profile = profile;
// Creating user account (Cf Accounts module)
Accounts.createUser(attr, function(error) {
console.log(error);
});
},
});
他再是我如何定義users
模式:
// Setting up Simple Schema (cf module)
var profile_schema = new SimpleSchema({
firstname: {
type: String,
regEx: /^[a-z0-9A-Z_]{3,15}$/
},
lastname: {
type: String,
regEx: /^[a-z0-9A-Z_]{3,15}$/
},
celular: {
type: String,
optional: true,
},
});
var schema = new SimpleSchema({
emails: {
type: [Object],
},
"emails.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email
},
"emails.$.verified": {
type: Boolean
},
profile: {
type: profile_schema,
optional: true,
},
createdAt: {
type: Date
},
});
// Attaching Simple Schema to the users collection (Cf collection2 module)
Meteor.users.attachSchema(schema);
我找不到什麼是不對的。任何建議是最受歡迎的!
嘗試添加這對您的架構 '服務:{ 類型:對象, 黑盒:真 }' – challett
這是工作。非常感謝。 我應該總是將'services'對象包含到我的用戶模式中,或者這是我的給定配置所要求的。我沒有使用任何'accounts-#service#'插件(即Twitter,Facebook,Google)。 再次感謝! –
沒問題。我把我的建議變成了答案,因爲它解決了你的問題。如果你還沒有看到它,你也可能對https://github.com/aldeed/meteor-autoform感興趣。它使得流星的形式非常簡單。 – challett