Rails: Validating min and max length of a string but allowing it to be blank

You can also use this format:

validates :foo, length: {minimum: 5, maximum: 5}, allow_blank: true

Or since your min and max are the same, the following will also work:

validates :foo, length: {is: 5}, allow_blank: true

Leave a Comment

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