1. 17:38 30th Jun 2009

    notes: 1

    validation_clusters

    A tiny Rails plugin that lets you use block syntax to specify multiple validations for a given field:

    class Person < AR::Base
      validates_presence_of :name
      
      validates_field :bio do |of|
        of.presence :on => :update
        of.length   :on => :update, :maximum => 140
      end
      
      # The above block is functionally identical to writing:
      validates_presence_of :bio, :on => :update
      validates_length_of   :bio, :on => :update, :maximum => 140
    end
    

    Available now* here: http://github.com/kylebragger/validation_clusters

    *Caveat: I haven’t gotten around to writing any tests for the plugin, as all testing was done before I extracted the code out of the application I originally wrote it for (and tested it within). But, you should write your own and submit them!

     
    1. kylewritescode posted this