How to validate text isn't blank in Rails

前端 未结 3 597
北荒
北荒 2020-12-15 03:32

if I do

  validates :body, :presence => true, :length => {:maximum => 30000, :message => \' is a bit long...\'}
  validates :body, :length =>         


        
3条回答
  •  星月不相逢
    2020-12-15 04:30

    What if you try adding something like this:

    validates_format_of :body, :with => /\A[[:graph:]]\Z/i
    

    Notes:

    • validates_format_of lets you validate with regex
    • [[:graph:]] lets you check a string for printable characters (see "Character Classes")

提交回复
热议问题