Created
March 27, 2018 20:02
-
-
Save stephancom/9f20852e9e038721c04e016dd1341249 to your computer and use it in GitHub Desktop.
Get valid values for a field with :inclusion validation via inspection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def valid_values(klass, kolumn) | |
klass.validators_on(kolumn).select { |v| v.is_a? ActiveModel::Validations::InclusionValidator }.first.options[:in].map(&:to_s) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment