我以前使用过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)
以下是检查电子邮件唯一性的WORKING操作:
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"
}
我的错误在哪里?