在数据库中将空白值保存为 nil [英] Save blank value as nil in database

查看:45
本文介绍了在数据库中将空白值保存为 nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,其中询问了一些信息.但某些值可以为空.但是,如果我多次保存带有一些空白值的公式,如果说该值已被采用.这是正常的,因为我使用过:validates_uniqueness_of

I have a web page where some information are asked. But some value can be blank. But if I save more than once my formulary with some blank value if says that Value has been already taken. This is normal since I used: validates_uniqueness_of

我的问题是:如果我将 value 保存为 nil,这个问题会解决吗??如果是,如何将值保存为 nil.或者其他解决方案是什么??

My question is: if I save value as nil, does this problem will be solved ?? If yes how save value as nil. Or what are others solutions please ??

提前致谢.

推荐答案

在文档中.

validates_uniqueness_of :my_value, :allow_blank => true

这篇关于在数据库中将空白值保存为 nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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