how to validate form ?

your validations should go into your model class, not in your controller. So to ensure that your user object has a username associated with it, put the following in your user.rb class:

validates_presence_of :username

and then an error will occur when you attempt to save a User object from your controller, using something like the following:

@user = User.new(params[:user])

if @user.save    #save was successful else    #save was unsuccessful, the error will be stored in the @user object end

you can then display the errors associated with an object by putting the following in your view code:

<%= error_messages_for :user %>

if you find that the built in validations don't do what you want, you can always override the validate method in your model, such as the following:

user.rb

def validate    errors.add(:username, "must not be john") if username == "john" end

Mike