How cat I get list of validations defined in model
Example:
class ModelName validates_presence_of :field_name validates_inclusion_of :sex, :in => %w(M F) end
I need Hash like:
{:field_name => 'required', :sex => 'Must be in: M, F'}
Gathering evidence to determine model validity is largely accomplished by examining the model structure (i.e., the algorithms and relationships) to see how closely it corresponds to the actual system definition. For models having complex control logic, graphic animation can be used effectively as a validation tool.
Model validation is the process by which model outputs are (systematically) compared to independent real-world observations to judge the quantitative and qualitative correspondence with reality.
The purpose of model validation is to check the accuracy and performance of the model basis on the past data for which we already have actuals.
You don't need a plugin for basic needs.
You can do this to get a hash of all validators.
ModelName.validators
If you want to get the validators for a specific field :
ModelName.validators_on(:attribute)
This code yields an array of required fields. It should be adaptable to your needs.
@required_fields = [] ModelName.validators.each do |v| @required_fields << v.attributes.first if v.kind == :presence end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With