Rails ActiveRecord: validate single attribute
问题 If there is a way I can validate single attribute in Rails? Something like: ac_object.valid?(attribute_name) I'm gonna use it for AJAX validation of particular model fields. Moving these validations to the Javascript makes code really ugly. 回答1: You can implement your own method in your model. Something like this def valid_attribute?(attribute_name) self.valid? self.errors[attribute_name].blank? end Or add it to ActiveRecord::Base 回答2: Sometimes there are validations that are quite expensive