次のように、モデルの検証にアクセスできます。
Model.validators
これらの特定の値を取得するには、次のようにします。
Model.validators_on(:height).select {|v| v.class == ActiveModel::Validations::InclusionValidator}.first.options[:in]
あなたの範囲を返します:
36..96
とを使用Range#minしRange#maxて整数値を取得できます。
すべてを便利にするために、次のようないくつかの方法を作成します。
class Model < ActiveRecord::Base
validates_inclusion_of :height, :in => 36..96, :allow_nil => true, :message => 'must be between 3 and 8 feet'
def self.min_height
validators_on(:height).select {|v| v.class == ActiveModel::Validations::InclusionValidator}.first.options[:in].min
end
end