简体   繁体   English

使用Rails一次进行服务器和客户端验证

[英]Server and client-side validation at once with Rails

The goal 目标

Creating model's validation once and use it both for the model and for the view. 一次创建模型的验证,然后将其用于模型和视图。

The problem 问题

I don't know the way. 我不知道

The scenario 场景

I'm creating an application in Ruby on Rails and I want to indicate that User's e-mail always will require at least 6 characteres to vaildate it, and I want to use that rule for client-side and server-side. 我正在Ruby on Rails中创建一个应用程序,我想表明用户的电子邮件始终需要至少6个字符来对其进行验证,并且我想在客户端和服务器端使用该规则。

What I actually need 我真正需要的

A light. 一盏灯。 A start. 一个开始。 I just have the user in the database and the model in Rails. 我只是在数据库中有用户,在Rails中有模型。

How to? 如何?

There is a gem client_side_validations which is no longer being maintained but appears to do what you want. 有一个gem client_side_validations ,它不再被维护,但似乎gem client_side_validations您的要求。 ( github link ) github链接

Its better to use rails4_client_side_validations. 最好使用rails4_client_side_validations。 It supports rails 4 also. 它还支持导轨4。 rails4_client_side_validations rails4_client_side_validations

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM