# Is there a "validates\_empty" method or a way to do this in a single line?

**URL:** <https://www.ruby-forum.com/t/is-there-a-validates-empty-method-or-a-way-to-do-this-in-a-single-line/152990>\
**Category:** Rails\
**Created:** [November 10, 2008, 10:32pm UTC](https://www.ruby-forum.com/t/is-there-a-validates-empty-method-or-a-way-to-do-this-in-a-single-line/152990 "2008-11-10T22:32:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [November 10, 2008, 10:32pm UTC](https://www.ruby-forum.com/t/is-there-a-validates-empty-method-or-a-way-to-do-this-in-a-single-line/152990/1 "2008-11-10T22:32:52Z")

</div>

Hi,

re Model validations: is there a “validates\_empty” method or a way to  
do this in a single line?

tks

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [November 10, 2008, 11:07pm UTC](https://www.ruby-forum.com/t/is-there-a-validates-empty-method-or-a-way-to-do-this-in-a-single-line/152990/2 "2008-11-10T23:07:03Z")

</div>

Hmm… maybe validates\_length\_of with max set to 0 (and a custom  
message)

Otherwise you may have to write your own validator using a callback  
like before\_create or before\_validation\_on\_create.

– Mark.
