Forum: Ruby on Rails Can anybody tell me step by step how validate data on form?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8c70506408fddb9740b4de7339055c77?d=identicon&s=25 Prashant Tiwari (tiwaripk)
on 2006-03-14 08:13
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
60159aebec931e98a932410491efbddf?d=identicon&s=25 David Ang (mickey)
on 2006-03-14 08:57
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 Tiwari 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
8c70506408fddb9740b4de7339055c77?d=identicon&s=25 Prashant Tiwari (tiwaripk)
on 2006-03-14 09:28
Hi,
I already tried the steps mentioned in the
"http://www.rails4days.pwp.blueyonder.co.uk/Rails4D.... 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 Tiwari 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
F3dc06f587d1ff4c7366b102bfda9204?d=identicon&s=25 David Mitchell (Guest)
on 2006-03-14 13:09
(Received via mailing list)
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.
This topic is locked and can not be replied to.