Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.
augustl edited this page Sep 12, 2010 · 16 revisions

Work-in-progress documentation. Feel fre to edit at will.

In an ideal world, this plugin works out of the box. There are a few things to be aware of, though. Here you go:

Configuration

The plugin allows configuration particular to the adapter you’re using. Refer to the documentation for the individual adapters:

validates_uniqueness_of: Making it work

Because your database is the only place where you can ask for uniqueness, this feature requires a controller callback. If you run a version of Rails older than 2.3, you will have to run the following command:

ruby script/generate live_validator

That’s because plugins couldn’t do controllers very easily back then. This adds a controller in your app/ folder, and adds some stuff to routes.rb.

validates_format_of: Regular expression handling

The regexp provided in your model will be displayed as-is to the javascripts. The plugin does not do anything to try to cope with differences between Ruby and JS regular expressions, so you can specify a JS specific regexp with the :live_validator option. A semi-sensible example:

validates_format_of :foo, :with => /\A[a-z]\z/, :live_validator => "/^[a-z]$/"

Validation messages

The plugin will ask the I18n library for validation messages. If you specify :message in your validation, this message will be used. Interpolating {model} is supported (such as :message => "is not as {model} as you might think"). Other I18n interpolations such as {{value}} and {{attribute}} is not supported.

Clone this wiki locally