How to validate form?

Hello there,

Rails is funny, I had been using PHP since 2001, and I learned many
other programmer language, but rails is hard to find around, the manual
is messy, you cannot get any good description from it as shown below!

Overwrite this method for validation checks on all saves and use
Errors.add(field, msg) for invalid attributes.

This above doesn’t help me anyway to know how to use this method :S:S:S:
and then I tried to find anything on google search results, and ended

if params[:user][:username].blank?
@errors << " missing"

*This again does aren’t working :(…

Can anyone help me out there to know how to get started, things are more
complicated then I thought, I don’t think you would like me to create
new topic every time I face a problem and use 1 hour on it.


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

#save was successful
#save was unsuccessful, the error will be stored in the @user object

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


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