我创建了自己的验证,使用 json - 如果用户电子邮件不是唯一的,则操作发送响应。这是行动:
def checkemail
 respond_to do |format|
  format.jsonr do
    if User.where(email: params[:email]).exists? 
      render :json => {
            :status  => :false,
            }.to_json
    else
      render :json => {
            :status  => :true,
            }.to_json
     end
    end
  end
end
第二种变体(不知道怎么用)
   def checkemail
   render :nothing
    if User.where(email: params[:email]).exists? 
      return false
    else
      true
    end
  end
我想编写一个自定义的 jQuery 验证方法,这里是代码:
   $.validator.addMethod("uniqueness", function(value) {
    $.getJSON('http://127.0.0.1:3000/checkemail.jsonr', { email: $('#email').val() }, function(data)  {
       return data.status
    });
}, 'Your email is not unique');
 .....
 "user[email]":{         //here is no error in name
    uniqueness: true
        },
也试过
它不断地告诉我电子邮件不是唯一的。
我想,我经常在我的自定义验证方法中发送 true 。
我的错误在哪里?