Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
28 lines (21 sloc) 1.17 KB

Simple plugin to extract validations from active-record to use them with jquery.validate and jquery.metadata


It adds the validation rules with custom error messages into the form markup, query.validate (with jquery.metadata which is needed to read the markup) reads them automaticly out. It requires the validation_reflection plugin (


script/plugin install git://

We are using it together with formtastic, that is what you need to add to formtastic:

def input(method, options = {})
options[:input_html] ||= {}
if @object && @object.class.respond_to?(:reflect_on_validations_for) && self.respond_to?(:build_validations)
  options[:input_html][:class] = [build_validations(@object, method, options), options[:input_html][:class]].join(" ")

It extracts :validates_presence_of, :validates_acceptance_of and validates_length_of validation rules It also adds :validates_uniqueness_of, to get this working you need to add an check method to the responding controller, this method has to implement the uniqueness validation

Tim Aßmann

Something went wrong with that request. Please try again.