Prabu Jayaraman
2011-Feb-03 10:55 UTC
How can check some field value existense in the table.
In the frontend ,i have a text box which accepts program id .If we gives value in that , it will get stored in sql database, but before storing i want to check whether the program id is exist in database. If exist then we instruct the user to give another program id. If not then ok to insert. how can i validate this input? Thanks in advance. Prabu Jayaraman -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2011-Feb-03 11:28 UTC
Re: How can check some field value existense in the table.
On 3 February 2011 10:55, Prabu Jayaraman <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> In the frontend ,i have a text box which accepts program id .If we gives > value in that , it will get stored in sql database, but before storing > i want to check whether the program id is exist in database. If exist > then we > instruct the user to give another program id. If not then ok to insert. > how can i validate this input?Use validates_uniqueness_of on the field, but also specify a unique key constraint in the database in order to ensure that a duplicate value cannot be saved, as validates_uniqueness_of can fail to detect duplicate values due to race conditions. 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.