Anh Hung Nguyen
2009-Sep-08 04:29 UTC
How to validate_uniqueness_of the joint of two attributes?
Hi, I have a form that asks users to put in their :first_name and :last_name. How do I validate that their full_name (first_name + last_name) is unique? Thanks! Nguyen Anh Hung Assistant Project Manager/ Consultant/ Business Analyst Tech Propulsion Labs Mobile: +84987 005 477 Twitter: http://www.twitter.com/anhhung Blog: http://www.fresco20.com Skype: anhhung.n | Yahoo: hero.tuxer | Gtalk: anhhung --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Abhinav Saxena
2009-Sep-08 07:15 UTC
Re: How to validate_uniqueness_of the joint of two attributes?
You can use :scope validates_uniqueness_of :first_name, :scope => :last_name If your database is huge, indexing last_name will help. Read more here: http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html Thanks, Abhinav -- अभिनव http://twitter.com/abhinav On Tue, Sep 8, 2009 at 9:59 AM, Anh Hung Nguyen <anhhung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi, > > I have a form that asks users to put in their :first_name and :last_name.How do I validate that their full_name (first_name + last_name) is unique?> > Thanks! > > Nguyen Anh Hung > Assistant Project Manager/ Consultant/ Business Analyst > Tech Propulsion Labs > Mobile: +84987 005 477 > Twitter: http://www.twitter.com/anhhung > Blog: http://www.fresco20.com > Skype: anhhung.n | Yahoo: hero.tuxer | Gtalk: anhhung > > > >--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---