Can anybody tell me step by step how validate data on form?

Hi,

I am new to ROR. I have created a form with foru fields in ROR. Now its
working fine for all CRUD operations. But I want to validate data on
form for “validates_presence_of” validation. How to do this?
I tried it by putting line “validates_presence_of :description” . But
its not working. Its throws error like “undefined method `each’ for
nil:NilClass”
Also what is “:description” in the “validates_presence_of :description”
? Is it a database column name or name of the field (textbox) on my form
that is responsible for holding value of description field?

Please help me.

Thanks in advaance.
Prash

hi there,

there’s a nice tutorial about validation somewhere on day 4 i think:

http://www.rails4days.pwp.blueyonder.co.uk/Rails4Days.pdf

-david

Prashant T. wrote:

Hi,

I am new to ROR. I have created a form with foru fields in ROR. Now its
working fine for all CRUD operations. But I want to validate data on
form for “validates_presence_of” validation. How to do this?
I tried it by putting line “validates_presence_of :description” . But
its not working. Its throws error like “undefined method `each’ for
nil:NilClass”
Also what is “:description” in the “validates_presence_of :description”
? Is it a database column name or name of the field (textbox) on my form
that is responsible for holding value of description field?

Please help me.

Thanks in advaance.
Prash

With “validates_presence_of :description”, “description” refers to a
field in your table. It goes in the model for one of your tables; the
“description” field will be in that table. When you go to create or
update a record in that table, the “description” field has to be
non-null.

The “undefined method ‘each’ for nil::NilClass” error is saying that
you’re trying to do an “each” iteration on an object that has a nil
value - you can’t do an ‘each’ on it because nil objects don’t have
subcomponents. Check for a typo in your code somewhere; if that
doesn’t help, use breakpoints to pause things at an appropriate spot
so you can check the values of your variables.

Regards

Dave M.

Hi,
I already tried the steps mentioned in the
http://www.rails4days.pwp.blueyonder.co.uk/Rails4Days.pdf”. But not
working. I m getting above error. Please help me. I am trying from last
2 days.
Thanx in advance.
Prash

David Ang wrote:

hi there,

there’s a nice tutorial about validation somewhere on day 4 i think:

http://www.rails4days.pwp.blueyonder.co.uk/Rails4Days.pdf

-david

Prashant T. wrote:

Hi,

I am new to ROR. I have created a form with foru fields in ROR. Now its
working fine for all CRUD operations. But I want to validate data on
form for “validates_presence_of” validation. How to do this?
I tried it by putting line “validates_presence_of :description” . But
its not working. Its throws error like “undefined method `each’ for
nil:NilClass”
Also what is “:description” in the “validates_presence_of :description”
? Is it a database column name or name of the field (textbox) on my form
that is responsible for holding value of description field?

Please help me.

Thanks in advaance.
Prash