Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Custom validation with rails: words with more than 26 characters (See related posts)

This goes in whatever model you're validating. "Subject" can be any of the symbols in your model and doesn't need the : in front of it.
def validate
	if subject.split.any?{|w| w.length > 26}
		errors.add(:subject, "cannot have words more than 26 consecutive characters")
	end
end

You need to create an account or log in to post comments to this site.


Click here to browse all 4839 code snippets

Related Posts