0

So far in my model I have:

validates :title, presence: true, length: { minimum: 40 }

I am building a rails app with text fields that need to be over a specific number of characters. My model covers the issue, I am interested in a constraint too.

I would like to protect my input on both ends if possible. I am aware of the constrain that prevents input over a maximum amount of characters as in "limit (50)" for example, but I have not seen the opposite anywhere. The only time I saw something close was MinLengthConstraint. Does anyone have an example usage of this?

jakebugz617
  • 319
  • 1
  • 11
  • 1
    This might be relevant: http://stackoverflow.com/questions/4426005/how-can-i-create-a-check-constraint-on-a-varchar-column-in-sql-server-specifying – Atri Sep 14 '15 at 18:34
  • What database? Solution probably is DB dependent. – Philip Hallstrom Sep 14 '15 at 18:55
  • you look this documentation?http://edgeguides.rubyonrails.org/active_record_validations.html#length – inye Sep 14 '15 at 19:49
  • @PhilipHallstrom postgres(SQL), I saw that documentation @inye and it seems to be only on validations, which I am able to achieve with `, length: { minimum: 40 }` . @ashutosh, I was looking at that question before this, it seems like VARCHAR, and [MinLengthConstraint] is potentially the most promising key words. – jakebugz617 Sep 17 '15 at 21:01

0 Answers0