Validates Uniqueness unless blank?

Hopefully this is an easy question...

I want to validate the uniqueness of a field, unless that field is
blank.. ie they didn't put anything in for it...

Any ideas? Thanks guys.

validates_uniqueness_of :field, :if {|model| !model.field.blank?}

what does do? I get the rest, little fuzzy on that one.

there's actually a typo there, it should be:

validates_uniqueness_of :field, :if => {|model| !model.field.blank?}

Using is just a short hand of using the following:

validates_uniqueness_of :field, :if => :some_field_is_not_blank?

def some_field_is_not_blank?

Here's some information about Proc from the Pickaxe book:

Proc objects are blocks of code that have been bound to a set of local
variables. Once
bound, the code may be called in different contexts and still access
those variables

def gen_times(factor)
return {|n| n*factor }

times3 = gen_times(3)
times5 = gen_times(5) ---> 36 ---> 25 ---> 60

Awesome thanks!

I figured out that the => was missing... worked perfectly! Thanks