I want to validate the uniqueness of a field if the field has a value. Is there anyway to do it? -- Posted via http://www.ruby-forum.com/.
Glenn Cadman wrote:> I want to validate the uniqueness of a field if the field has a value. > Is there anyway to do it?Sure, you can use the following syntax: validates_presence_of :field, :if => .. So you can do anything you would do in a normal if. David -- Posted via http://www.ruby-forum.com/.
Glenn Cadman
2006-May-26 09:59 UTC
[Rails] Re: validates_uniqueness_of but only when exists
David wrote:> Glenn Cadman wrote: >> I want to validate the uniqueness of a field if the field has a value. >> Is there anyway to do it? > > Sure, you can use the following syntax: > > validates_presence_of :field, :if => .. > > So you can do anything you would do in a normal if. > > DavidThanks, working well. validates_uniqueness_of :employeenumber, :if => employeenumber? -- Posted via http://www.ruby-forum.com/.