Validating if record exists by name

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.

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.

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-

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])