0

我过去曾使用过 jQuery 远程功能,但在这种情况下我遇到了麻烦。

我有一个有效的远程功能来检查电子邮件的唯一性,但现在我想检查用户密码,当他使用 jQuery 验证插件(如果可能的话)输入它时,但我经常进入 Firebug:

 406 Not acceptable

这是我的行动(问题在这里。编辑): -编辑

def checkpass 
 @user = User.find_by_email(params[:email])
  if  @user && @user.valid_password?(params[:user][:password])
   @check = true
  end
  respond_to do |format|
   format.json { render :json => @check }
 end
end

从控制台: -编辑

    Started GET "/checkpass?user%5Bpassword%5D=[FILTERED]&email=new%40mail.com" for   127.0.0.1 at 2012-09-30 11:42:26 +0300
   Processing by EditUserController#checkpass as JSON
   Parameters: {"user"=>{"password"=>"[FILTERED]"}, "email"=>"new@mail.com", "pas
   sword"=>"[FILTERED]"}
 ←[1m←[36mUser Load (0.0ms)←[0m  ←[1mSELECT "users".* FROM "users" WHERE "users
   "."email" = 'new@mail.com' LIMIT 1←[0m
  User: new@mail.com
  Pass: 123456
  Devise pass:true
  Completed 200 OK in 438ms (Views: 15.6ms | ActiveRecord: 0.0ms)

这是检查电子邮件唯一性的有效操作:

 def checkemail
  @user = User.find_by_email(params[:user][:email])
   respond_to do |format|
    format.json { render :json => !@user }
   end
end

和我的 jQuery 远程功能验证 -编辑

     $("#edit_password").validate({
   rules: {

        "user[password]":{
            required: true,
            minlength: 6,
            remote: {
            url: "http://127.0.0.1:3000/checkpass",
            type: "get",
            data: {
              email: function() { return $("#user_email").val(); }
            }
        },
   ...
  })

checkuniqeness jQuery 的工作示例:

    "user[email]": {
          required: true,
          email: true,
          remote: {
          url: "http://127.0.0.1:3000/checkemail"
          }

我的错误在哪里?

4

0 回答 0