-1

I'm trying to find a way to reject creation of a message if the form filled out is empty (including spaces and new lines). Currently I have the form set to required: true but that doesn't stop a user from hitting the spacebar and sending the message. I don't know if Rails has a built in validation or if there is some regex I would have to use.

Antonio
  • 731
  • 7
  • 28

1 Answers1

0

You're after a presence validator in your model. It will explicitly require that your field's present? be true, which it won't be if the column contains only whitespace.

user229044
  • 232,980
  • 40
  • 330
  • 338