hey guys, i have looked alot of places and seen screencasts on validation but i still dont understand how to go about validating a form to check if the record exists by the name entered in. lets say a project, has users assigned to the project, and we want to assign users by using a textbox for their username. how would we do the validation in the model? i know i can simply write an if statement for manually checking the textbox value and doing a find in the controller, but it seems a bit messy. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Chubbs wrote:> hey guys, i have looked alot of places and seen screencasts on > validation but i still dont understand how to go about validating a > form to check if the record exists by the name entered in. > > lets say a project, has users assigned to the project, and we want to > assign users by using a textbox for their username. > > how would we do the validation in the model? > > i know i can simply write an if statement for manually checking the > textbox value and doing a find in the controller, but it seems a bit > messy.Try validates_uniqueness_of in the model. -- 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 -~----------~----~----~----~------~----~------~--~---
but thats good for checking if for a user id, but i have the name of the user On Jan 28, 12:36 am, Jeremy Weiskotten <rails-mailing-l...@andreas- s.net> wrote:> Chubbs wrote: > > hey guys, i have looked alot of places and seen screencasts on > > validation but i still dont understand how to go about validating a > > form to check if the record exists by the name entered in. > > > lets say a project, has users assigned to the project, and we want to > > assign users by using a textbox for their username. > > > how would we do the validation in the model? > > > i know i can simply write an if statement for manually checking the > > textbox value and doing a find in the controller, but it seems a bit > > messy. > > Try validates_uniqueness_of in the model. > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
Chubbs wrote:> but thats good for checking if for a user id, but i have the name of > the user > > On Jan 28, 12:36 am, Jeremy Weiskotten <rails-mailing-l...@andreas-In your original post, you asked how you could do the validation in the model, but I don''t think you want to do validation. You want to do a lookup by name in order to link something to a user''s account. user = User.find_by_name(params[:name]) -- 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 -~----------~----~----~----~------~----~------~--~---