No, allowing blank is fine, the validation is this: validate_uniqueness_of(:email, :allow_blank => true)
The issue is writing the test. On Jun 17, 10:47 am, Colin Law <clan...@googlemail.com> wrote: > On 17 June 2010 09:18, pepe <p...@betterrpg.com> wrote: > > > > > > > On Jun 17, 1:28 am, J. Pablo Fernández <pup...@pupeno.com> wrote: > >> Where do you pass that? > > >> should validate_uniqueness_of(:email, :allow_blank => true) > > >> That doesn't work. That method takes only one argument: > > group/rubyonrails-talk?hl=en. > > >> -- > >> J. Pablo Fernández <pup...@pupeno.com> (http://pupeno.com) > > > Here is a link to the validation method doc: > > >http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMeth... > > > You should be able to use :allow_blank => true, unless your version of > > Rails does not support the option, which I guess could be possible? If > > that is the case you should be able to use :if or :unless: > > > Supposing your model is for a customer: > > > # The 'c' inside the proc represents the customer record you're > > validating (you can, of course, use any variable name you want). > > validate_uniqueness_of :email, :unless => Proc.new {|c| > > c.email.blank?} > > > You have to take into consideration that if your DB table has a unique > > constraint on the e-mail column you'll still run into problems because > > the DB itself will not let you add 2 records with an empty e-mail > > address, only one. The second attempt will fail. > > Is the solution to allow null for the email rather than empty string? > Will the unique constraint fail in that case? > > Colin -- 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-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.