I want to skip validations based on attributes. If certain attributes are not in form so I do not want to validate them.Currently, if I post them from one form which has 1 field, it still validates other 9 fields and show me errors that it cant be blank.If I check from big form which has 10 fields, it passes successfully.The below code did trick for me but my main intention is to refactor so it will fullfil its purpose as i stated above.Code is:validates :teacher_number, presence: true, if: teacher_number && teacher_number.blank?  validates :title, presence: true, if: title && title.blank?  validates :name, presence: true, if: name && name.blank?  validates :gender, presence: true, if: gender && gender.blank?  validates :location, presence: true, if: location && location.blank?  validates :dob, presence: true, if: dob && dob.blank?  validates :contact_mobile, presence: true, if: contact_mobile && contact_mobile.blank?  validates :contact_home, presence: true, if: contact_home && contact_home.blank?  validates :street, presence: true, if: street && street.blank?  validates :city, presence: true, if: city && city.blank?  validates :state, presence: true, if: state && state.blank?  validates :zip_code, presence: true, if: zip_code && zip_code.blank?  validates :country, presence: true, if: country && country.blank?  validates :teacher_number, uniqueness: {scope: :school_id}, if: teacher_number && teacher_number.blank?  validate  :teacher_number_existance, :on => :create, if: self.teacher_number && self.teacher_number.blank?  validate  :school_existance, :on => :create, if: self.teacher_number && self.teacher_number.blank?I simply wants to do something like:before_validation :skip_validationsdef strip_validations    [:teacher_number, :title, :name, :gender, :location, :dob, :contact_mobile, :contact_home, :street, :city, :state, :zip_code, :country].each do |attr|      errors.add(Teacher,  #{attr} can't be blank) if attr && attr.blank?    end  endBut above code does not work for my cases. Any good work around?
Validating only attributes that are present in a form
ruby;ruby on rails;validation
You just need to change the method call from skip_validation to strip_validations.before_validation :strip_validations    def strip_validations      ['teacher_number', 'title', 'name', 'gender', 'location', 'dob', 'contact_mobile', 'contact_home', 'street', 'city', 'state', 'zip_code', 'country'].each do |attr|        errors.add(Teacher,  #{attr} can't be blank) if send(attr.to_sym) && send(attr.to_sym).blank?      end    endfor more specific error messages you can useerrors.add(Teacher, {attr =>  #{attr} can't be blank}) if send(attr.to_sym) && send(attr.to_sym).blank?