Rails 4 客户端验证 [英] Rails 4 client side validation
问题描述
自从将我的网站升级到 Rails 4 后,客户端验证 gem 已停止为我工作.我查看了各种替代方案,例如 jquery-validation-rails 和 Judge,它们涉及编写相当多的 javascript,尤其是对于如此大的站点.在 jquery-validation-rails 的情况下,重新执行客户端的所有验证规则.考虑到 Rails 是一个如此流行的框架,让我感到惊讶的是没有简单"的选择.是否有其他人知道的任何 gem,它进行验证以及客户端验证 gem?
Since upgrading my site to Rails 4, the client-side-validations gem has stopped working for me. I have had a look at the various alternatives such as jquery-validation-rails and judge, which involve writing quite a bit of javascript, especially for a site so large. And in the case of jquery-validation-rails, re-doing all the validation rules client side. Considering Rails is such a popular framework, it surprises me that there is no 'easy' option. Is there any gem which anyone else is aware of, which does validation as well as the client-side-validation gem?
或者是将 ModelName.validators 方法与一些 ajax 混合使用,并通过 jquery-validation-rails gem 进行验证的最佳替代方法?
Or is the best alternative to use the ModelName.validators method mixed with some ajax, and do the validation through the jquery-validation-rails gem?
推荐答案
来自 Google.
http://rubygems.org/gems/rails4_client_side_validations
https://github.com/amatsuda/html5_validators
此外,这个家伙似乎已经通过使用 4-0-beta 分支获得了您用来工作的相同宝石.
Also this guy seemed to have gotten the same gem you are using to work by using the 4-0-beta branch.
如果 4-0-beta 分支适合您,请考虑帮助维护 gem 以使其保持活力.
If the 4-0-beta branch works for you, consider helping to maintain the gem to keep it alive.
在你的 Gemfile 中使用特定的 git repo 版本:
To use a certain git repo version in your Gemfile:
gem 'client-side-validations', :git => 'https://github.com/bcardarella/client_side_validations/tree/4-0-beta'
这篇关于Rails 4 客户端验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!