Skip to content

Instantly share code, notes, and snippets.

@stephancom
Created March 27, 2018 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephancom/9f20852e9e038721c04e016dd1341249 to your computer and use it in GitHub Desktop.
Save stephancom/9f20852e9e038721c04e016dd1341249 to your computer and use it in GitHub Desktop.
Get valid values for a field with :inclusion validation via inspection
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