title: DRY way to correct fields with the same validation
body: <p>I have several tables in Rails that have string fields that must match a set of terms specified by a table, CvTerm (short for controlled_vocabulary). CvTerm serves as a table-and-field specific whitelist; for example, table <code>Foo</code> might have a field <code>Bar</code> for which the only allowed entries are <code>Baz</code>, <code>Bax</code>, or <code>Quux</code>, for which there would be CvTerms created for each allowed entry.</p>
  
  <p>I wrote a custom validator to ensure that the value a user assigns to these fields matches one of those set for the table; this validator can be used across all models as a one-liner, <code>validates :field, is_controlled: true</code>.</p>
  
  <pre><code>class IsControlledValidator &lt; ActiveModel::EachValidator
      def validate_each(record, attribute, value)
          if options[:has_context]
              allowed_terms = CvTerm.where({
                  :related_table =&gt; record.class.to_s,
                  :related_field =&gt; attribute.to_s,
                  :context_table =&gt; record.related_type
              }).map(&amp;:term)
          else
              allowed_terms = CvTerm.where(:related_table =&gt; record.class.to_s, :related_field =&gt; attribute.to_s).map(&amp;:term)
          end
          unless allowed_terms.include?(value)
              record.errors[attribute] &lt;&lt; "must be included in the allowed terms:\n#{allowed_terms.join("\n")}"
          end
      end
  end
  </code></pre>
  
  <p>This is convenient to implement in my models and works nearly as intended, but it's case-sensitive: It would be quite annoying to force the user to manually ensure the case is exactly the same as the initially input allowed term.</p>
  
  <p>Apart from putting such a case-correction in the validator, which I understand is frowned upon, is there a way to do this that doesn't require me to individually case-correct every controlled field? </p>