2009
03.29

If you want to write your own custom validation – Say each part of the name should be only 20 characters long – here is how you can do it. Add a callback called validate in the model and here is how it looks

def validate
	if name.split.any?{|w| w.length > 20}
		errors.add(:name, "cannot have name more than 20 consecutive characters")
	end
end

No Comment.

Add Your Comment