Rails 3:client_side_validations宝石和设计密码验证 [英] Rails 3: client_side_validations gem and devise password validations

查看:140
本文介绍了Rails 3:client_side_validations宝石和设计密码验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的client_side_validations宝石在我的表单上工作得很好。我正在为我的用户模型使用Devise,当我转到edit_user_registration表单时,将会为所有其他所有内容提供验证:current_password,:password和password_confirmation字段。

I've got the client_side_validations gem working really great on my forms. I'm using Devise for my users model and when I go to the edit_user_registration form, validations are thrown up for everything except the :current_password, :password, and :password_confirmation fields.

Fort实例是我留下的电子邮件空白,当我打开该字段时,验证会弹出。但是,如果我将current_password字段留空,并且tab从中没有发生任何事情,那么当我提交表单时,我收到错误1错误禁止此用户被保存:密码不能为空

Fort instance is I leave the email blank, the validation pops up right when I tab out of the field. However, if I leave the current_password field blank and tab out of it nothing happen, then when I submit the form I get the error "1 error prohibited this user from being saved: password can't be blank"

感谢任何帮助

http:// pastie。 org / 1907464

推荐答案

目前ClientSideValidations将过滤任何条件验证器。 Devise将一些验证器设置为条件: https://github.com/plataformatec/devise/blob/master/lib/devise/models/validatable.rb#L24-32

Currently ClientSideValidations will filter out any conditional validators. Devise sets some of the validators as conditional: https://github.com/plataformatec/devise/blob/master/lib/devise/models/validatable.rb#L24-32

原因我这样做是因为客户端没有好的方法来确定该条件的真正价值。我可以在表单生成时做到这一点,但是如果条件依赖于可以在表单上更改的值,该怎么办?所以我选择过滤它们,让事情回到服务器。

The reason I did this is because there is no good way for the client to determine the true value of that conditional. I could do it at the time the form is generated but what if that conditional relied upon a value that could be changed on the form? So I opted to filter them and let things fall back to the server.

这是一个想法,但显然它对某些事情造成了不公平的限制。这是最明显的(和受欢迎的)。

That was the idea but clearly it has imposed unfair limitations on some things. This being the most obvious (and popular).

所以我打算尽快发布一个新版本,这将允许你显式地覆盖条件过滤器。它将像这样工作:

So I plan on releasing a new version very soon that will allow you to explicitly override the conditional filters. It will work like this:

<%= f.text_field :password, :validate => { :presence => true, :confirmation => true } %>

<%= f.text_field :password, :validate => true %>

在第一种情况下,您可以选择哪些验证器关闭过滤器。在第二种情况下,将关闭该属性的所有验证器的过滤器。条件将在生成表单时进行评估,如果通过,则将验证器添加到客户端使用的输入元素。

In the first case you can choose which validators to turn the filter off. In the 2nd case it will turn the filter off for all validators on that attribute. The conditional will be evaluated at the time the form is generated and if it passes it will add the validator to the input element for use on the client.

这篇关于Rails 3:client_side_validations宝石和设计密码验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆