我需要检查登录用户的电子邮件和密码是否正确,但是当我为一个字段调用远程时 - 我在 params 中没有其他字段值。
这是我检查凭据的操作:
def checkpass
user = User.find_by_email(params[:user][:email])
logger.debug "User: #{params[:user][:email]}"
logger.debug "Pass: #{params[:user][:password]}"
logger.debug "Devise pass:#{user.valid_password?(params[:user][:password])}"
respond_to do |format|
if user && user.valid_password?(params[:user][:password])
format.json { render :json => user }
end
end
end
jQuery 验证(编辑):
'user[password]': {
required: true,
minlength: 6,
remote: {
url: "http://127.0.0.1:3000/checkpass",
type: "get",
data: {
email: function() { return $("#user_email").val(); }
}
}
日志
Processing by EditUserController#checkpass as JSON
Parameters: {"user"=>{"password"=>"[FILTERED]"}, "email"=>"user@mail.com", "pa
ssword"=>"[FILTERED]"}
←[1m←[35mUser Load (0.0ms)←[0m SELECT "users".* FROM "users" WHERE "users"."e
mail" IS NULL LIMIT 1
User:
Pass: 123456
我怎样才能同时获得 params[:email] 和 params[:password] ?