Hi - I want to allow duplicate fields values if the field is blank, but disallow duplicates if it''s not. Is there a validates_uniqueness_of_if_present equivalent? Thanks, Dino --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You can use :allow_nil or :allow_blank attributes to it like validates_uniqueness_of :email, :allow_nil => true this would skip the validation if field is nil. :allow_blank works same way on empty strings. And then all/most validations com with the :if and :unless options that would allow for more detailed determination if the validation should be used --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
dino d. wrote:> Hi - I want to allow duplicate fields values if the field is blank, > but disallow duplicates if it''s not. Is there a > validates_uniqueness_of_if_present equivalent? > > Thanks, > DinoHi, As you required to place duplicate value if field is blank than you just use validates_uniqueness_of :field_name,:allow_blank => ''true'' :allow_nil - If set to true, skips this validation if the attribute is nil (default is false). :allow_blank - If set to true, skips this validation if the attribute is blank (default is false). -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---