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

**URL:** <https://www.ruby-forum.com/t/can-anybody-tell-me-step-by-step-how-validate-data-on-form/54788>\
**Category:** Rails\
**Created:** [March 14, 2006, 8:13am UTC](https://www.ruby-forum.com/t/can-anybody-tell-me-step-by-step-how-validate-data-on-form/54788 "2006-03-14T08:13:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tiwaripk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7ab992/32.png) [@tiwaripk](https://www.ruby-forum.com/u/tiwaripk)\
**Post date:** [March 14, 2006, 8:13am UTC](https://www.ruby-forum.com/t/can-anybody-tell-me-step-by-step-how-validate-data-on-form/54788/1 "2006-03-14T08:13:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tiwaripk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7ab992/32.png) [@tiwaripk](https://www.ruby-forum.com/u/tiwaripk)\
**Post date:** [March 14, 2006, 8:57am UTC](https://www.ruby-forum.com/t/can-anybody-tell-me-step-by-step-how-validate-data-on-form/54788/2 "2006-03-14T08:57:58Z")

</div>

hi there,

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

[http://www.rails4days.pwp.blueyonder.co.uk/Rails4Days.pdf](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

---

<div class="post-metadata">

**Author:** ![tiwaripk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7ab992/32.png) [@tiwaripk](https://www.ruby-forum.com/u/tiwaripk)\
**Post date:** [March 14, 2006, 1:09pm UTC](https://www.ruby-forum.com/t/can-anybody-tell-me-step-by-step-how-validate-data-on-form/54788/3 "2006-03-14T13:09:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tiwaripk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7ab992/32.png) [@tiwaripk](https://www.ruby-forum.com/u/tiwaripk)\
**Post date:** [March 14, 2006, 9:28am UTC](https://www.ruby-forum.com/t/can-anybody-tell-me-step-by-step-how-validate-data-on-form/54788/4 "2006-03-14T09:28:45Z")

</div>

Hi,  
I already tried the steps mentioned in the  
“[http://www.rails4days.pwp.blueyonder.co.uk/Rails4Days.pdf](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](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
