当我在Meteor应用程序上创建一个帐户时,我会在几次检查每个元素的有效性。然后我创建了用户。如果没有出现错误,我会显示成功div,而另一个则显示错误。
Accounts.createUser(options ,function(err){
if(err){
console.log("rorororororroro");
if(err.message == "Email already exists. [403]"){
Session.set('error', regAlert("This email adress already exists", tmpl));
}else{
Session.set('error', regAlert("Sorry, but an unidentified error occured. Please retry later. If the error persists, contact the support"));
}
}else if(Meteor.call('talknameIsAvailable', talkname)){
Session.set('error', regAlert("A user with this talkname already exists", tmpl));
}
});
if(!Session.get('error')){
$('#register-success').show("slow");
//console.log("[SUCCESS] Account created");
//document.location.href="/";
}else{
$('#register-error').show("slow");
}
问题是我总是显示成功div,因为最后if / else
是在回调设置错误会话var之前计算的,当电子邮件已被使用时。
Meteor处理这种情况的最佳方式是什么?
谢谢你
答案 0 :(得分:0)
当Session.get("错误")未定义时,(!Session.get(" error"))返回true。
尝试:
def listado_publicaciones
if params[:publicaciones]
@Publicaciones = params[:publicaciones]
else
@Publicaciones = Proyecto.where("concurso_id","=",@concurso.id).as_json({:include => [:creador => {:only =>[:id],:include =>[:ficha =>{:only =>[:nombres,:apellidos], :methods => [:fullname],:include => [:publicacions => {:only =>[:id,:omitir,:anio,:titulo,:revista_nombre,:primer_autor,:autor_correspondiente,:coautor,:estado_id],:include => [:subtipo]}]}]}]})
end
respond_to do |format|
format.html
format.json { render :json => @Publicaciones}
format.xlsx
end
end
答案 1 :(得分:0)
我在.wait()
函数的末尾添加了createUser
:
Accounts.createUser(options ,function(err){
if(err){
console.log("rorororororroro");
if(err.message == "Email already exists. [403]"){
Session.set('error', regAlert("This email adress already exists", tmpl));
}else{
Session.set('error', regAlert("Sorry, but an unidentified error occured. Please retry later. If the error persists, contact the support"));
}
}else if(Meteor.call('talknameIsAvailable', talkname)){
Session.set('error', regAlert("A user with this talkname already exists", tmpl));
}
}).wait();