# ERb with nested loops-- NG!

**URL:** <https://www.ruby-forum.com/t/erb-with-nested-loops-ng/109285>\
**Category:** Ruby\
**Created:** [July 13, 2007, 4:20am UTC](https://www.ruby-forum.com/t/erb-with-nested-loops-ng/109285 "2007-07-13T04:20:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [July 13, 2007, 4:20am UTC](https://www.ruby-forum.com/t/erb-with-nested-loops-ng/109285/1 "2007-07-13T04:20:57Z")

</div>

How do you do nested loops in ERb?  
Is it possible?  
Every time I attempt it, ERb barfs.

Oh, and how can you require a .rb file and use its methods in ERb files?  
Does the require line need to be in the erb.cgi file?

John J.

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [July 13, 2007, 10:26am UTC](https://www.ruby-forum.com/t/erb-with-nested-loops-ng/109285/2 "2007-07-13T10:26:37Z")

</div>

On 7/13/07, John J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> How do you do nested loops in ERb?  
> Is it possible?  
> Every time I attempt it, ERb barfs.

I see no problem there. Could you post your attempt to see what’s wrong?

> Oh, and how can you require a .rb file and use its methods in ERb files?  
> Does the require line need to be in the erb.cgi file?

I think ‘require’ can be put anywhere. It always 'require’s to the top  
level context.

J.

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [July 13, 2007, 6:14pm UTC](https://www.ruby-forum.com/t/erb-with-nested-loops-ng/109285/3 "2007-07-13T18:14:01Z")

</div>

On Jul 13, 2007, at 3:25 AM, Jano S. wrote:

> > Does the require line need to be in the erb.cgi file?
> 
> I think ‘require’ can be put anywhere. It always 'require’s to the top  
> level context.
> 
> J.

Actually could anyone post some examples of ERb for web pages, but  
non-Rails?  
Particularly I’d like to look at the requires and how nested loops  
are handled,  
but more to the point, I’m wondering if the cgi file that calls Ruby  
is part of the problem.  
Cgi is a big mystery to me.  
Every text goes over it quickly and assumes you know it from Perl.
