加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 一次验证单独案例的最小和最大长度

发布时间:2020-12-17 02:59:33 所属栏目:百科 来源:网络整理
导读:我验证了这样的姓氏字段 validates :surname,:presence = true,:length = { :within = min_surname_length..max_surname_length,:message = "is bad (minimum is #{min_surname_length},maximum is is #{max_surname_length})" } 但是我希望在没有单独语法验
我验证了这样的姓氏字段

validates :surname,:presence       => true,:length         => { :within => min_surname_length..max_surname_length,:message => "is bad (minimum is #{min_surname_length},maximum is  is #{max_surname_length})" }

但是我希望在没有单独语法验证的情况下将最小值和最大值分开

validates_length_of :name,:minimum => 3
validates_length_of :name,:maximum => 30

简而言之,我想做这样的事情(我知道,这是错的):

validates :surname,:message => "is bad (minimum is #{min_surname_length}" IF MINIMUM,:message => "is bad (maximum is  is #{max_surname_length})" IF MAXIMUM }

怎么可能一次做到这一点?

这是我将如何使用它:

validates :surname,:length         => { :within => min_password_length..max_password_length,:too_short => 'too short message',:too_long => 'too long message' }

解决方法

validates_length_of :surname,:within => 3..30,:too_long => 'too long message'

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读