How to validate text isn't blank in Rails

前端 未结 3 600
北荒
北荒 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:24

    presence: true already does that according to http://guides.rubyonrails.org/active_record_validations.html#presence

    This helper validates that the specified attributes are not empty. It uses the blank? method to check if the value is either nil or a blank string, that is, a string that is either empty or consists of whitespace.

提交回复
热议问题