`
yacole
  • 浏览: 238305 次
  • 性别: Icon_minigender_1
  • 来自: 浙江科技学院
社区版块
存档分类
最新评论

校验辅助方法Validation Helpers

阅读更多

Validation Helpes
校验辅助方法
---------[方法]------------------[选项]-----------------------------------
calidates_acceptance_of       :message 文本 默认值为 "must be accepted."   #检查单元框(checkbox)是否被选中
                              :on           :save、:create或是:update
validates_associated          :message 文本 默认值为 "is invalid."         #对惯量对象进行校验
                              :on           :save、:create或是:update
validates_confirmation_of     :message 文本 默认值为 "doesn't match confirmation."  #校验一个字段及其确认字段拥有相同的内容
                              :on           :save、:create或是:update
validates_each                :allow_nil boolean 如果:allow_nil值为true,  #在代码块中校验一个或多个属性
                                                 值为nil的属性将不会被传递给代码块进行校验。
                                                 缺省值为false(即:需要校验值为nil的属性)
                              :on           :save、:create或是:update 
validates_exclusion_of        :allow_nil    如果为true,则不检查值为nil的属性  #校验属性值不在指定的一组值之中
                              :in(或:within) enumerable 一个enumerable对象-枚举类型
                              :message 文本  缺省值为"is reserved."
                              :on           :save、:create或是:update
validates_format_of           :message 文本 缺省值为"is invlid."   # 校验属性值是否匹配一个正则表达式
                              :on           :save、:create或是:update
                              :with    用于校验属性值的正则表达式
validates_inclusion_of        :allow_nil 如果该选项值为true,则不检验值为nil的属性   #校验指定的属性值是否出现在一组指定的值中
                              :in(或:within) enumerable 一个enumerable对象-枚举类型
                              :message  文本 缺省值为"is not included in list."
                              :on           :save、:create或是:update
vlaidates_length_of           :in(或within)  range 属性的长度必须在此范围内    #校验属性值的长度
                              :is integer 属性值的长度必须恰好与此相等
                              :minimum integer 属性值的字符数不能少于这个值
                              :maximum integer 属性值的字符数不能多于这个值
                              :message 文本 不同校验条件有不同的缺省的出错信息。可以在此信息中包含
                                            一个%d标记,该标记将被替换成校验条件的长度值
                              :on           :save、:create或是:update
                              :too_long 文本 如果使用了:maximum选项,用该选项来指定出错信息
                              :too_short 文本 如果使用:minimum选项,用该选项来制定出错信息
                              :wrong_length 文本 如果使用了:is选项,用该选项来指定出错信息
calidates_numbericality_of    :message 文本 缺省值为"is not a number"  #校验指定属性是合法的
                              :on           :save、:create或是:update
                              :only_integer 如果为true,则属性值则该属性只能由(可选的)正负号及一个或多个数字组成
validates_presence_of         :message 文本 缺省值为"can't be empty"   #校验指定属性不为空
                              :on           :save、:create或是:update
validates_uniqueness_of       :message 文本 缺省值为"has already been taken"   #校验属性值的唯一性
                              :on           :save、:create或是:update
                              :scope 属性名 只针对该字段值与当前模型对象相同的那些记录进行检查


 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics