我如何使用Rails仅在注册时验证某些字段 [英] How do I validate certain fields with rails devise on registration only

查看:49
本文介绍了我如何使用Rails仅在注册时验证某些字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组自定义字段,这些字段附加到名为Entrant的设计模型上.

I have a set of custom fields attached to a devise model called Entrant.

我有两种形式,一种是注册表格(三个字段),另一种是在帐户区域(12个字段).大多数自定义字段区域都是必需的,但仅在表格中位于帐户区域中.

I have two forms, one for registration form (three fields) and one which sits in the account area (12 fields). Most of the custom fields area required but only within the form the sits in the account area.

我该如何实现?

我正在使用Rails 4.2和ruby 2.1

I am using rails 4.2 and ruby 2.1

推荐答案

您可以简单地指定对动作的验证,即:

You can simply specify validations on actions, that is:

validates :name, presence: true, on: :create # which won't validate presence of name on update action

如果您询问将自定义字段放在何处,则生成devise的视图并使用这些字段更新相应的视图.

If you ask where to put your custom fields, then generate devise's views and update corresponding ones with these fields.

这篇关于我如何使用Rails仅在注册时验证某些字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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