How to validate text isn’t blank in Rails

Rails adds the handy method blank? which checks for false, nil and empty strings as described here.
Rails also adds the handy validator allow_blank: false.

So in your case it should be:

validates :body, presence: true, allow_blank: false


Edit (original answer above):

As stated in the answer below, allow_blank: false is not needed as that’s the default behaviour of presence: true.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)