新手问题 Rails 中数据库验证和 model 验证为什么要分开弄两套?

zealinux · September 22, 2012 · Last by Rei replied at September 24, 2012 · 2413 hits

Rails 中数据库(migration)中加了验证,然后 model 中再加一次。

有什么好办法只加一次?

还是数据库不加验证了

我不觉得数据库里的那个算验证呢?

migration 加验证是什么意思呀~

不是所有数据库都有验证的,而且数据库验证的逻辑没有应用层丰富。数据库验证一般就用来校验一些字段不能为空。

Rails 刚开始设计的时候就没打算在数据库里面加验证:trollface:

但感觉如果数据库支持的话,还是加一个 foreign_key constrain 会比较好

其实还要做一套前端验证。之前用 client_side_validation,不过感觉不太灵活,还是得写 js。

You need to Sign in before reply, if you don't have an account, please Sign up first.