Reputation: 343
I have an ActiveRecord validator of
validates :content, length: { in: 1..400 }
In my view I would like to show the maximum allowed character length (400) by referring to the validator (so that I am not setting the value of 400 in more than one spot). I'm using Rails 4. Any suggestions on what would a good approach? Thanks.
Upvotes: 0
Views: 158
Reputation: 29349
Model.validators_on(:content).find{|v| v.class == ActiveRecord::Validations::LengthValidator}.options[:maximum]
Upvotes: 1