I am manually creating objects in the rails console using Model.new(<attributes here>)
. Is there an easy way to list out which attributes a model will require me to include in order for the .save
call to succeed?
I am running rails 4.2.3
You can get an array of validators using Model.validators
. You'll have to parse this in some way to extract those validations for presence, something like:
presence_validated_attributes = Model.validators.map do |validator|
validator.attributes if validator.is_a?(ActiveRecord::Validations::PresenceValidator)
end.compact.flatten