# Looping through arrays in View?

**URL:** <https://www.ruby-forum.com/t/looping-through-arrays-in-view/114678>\
**Category:** Rails\
**Created:** [September 17, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/looping-through-arrays-in-view/114678 "2007-09-17T13:24:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pgega](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ba9def/32.png) [@pgega](https://www.ruby-forum.com/u/pgega)\
**Post date:** [September 17, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/looping-through-arrays-in-view/114678/1 "2007-09-17T13:24:03Z")

</div>

Hi there ,

I found the specific bug in my code. Truly saying I still did not find  
the bug . so I am writing now.

I am looping through database records in my view

\<% for blue\_widget in @blue\_widgets %\>

\<% if blue\_widget.B == 1 and blue\_widget.B == 1 %\>  
…some code  
\<% if blue\_widget.a == 0 and blue.widget == 1 %\>  
…come code for second condition  
\<% end %\>  
\<% else %\>  
…code for rest cases  
\<% end %\>

\<% end %\>

The question in way all of records do the ELSE condition despite of  
fact they should do the first or second IF ?  
Is the problem that I can not loop through the arrays in this way?

Best regards ,

Pg

---

<div class="post-metadata">

**Author:** ![pgega](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ba9def/32.png) [@pgega](https://www.ruby-forum.com/u/pgega)\
**Post date:** [September 17, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/looping-through-arrays-in-view/114678/2 "2007-09-17T13:24:05Z")

</div>

2007/9/17, pgega [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Hi there ,
> 
> I found the specific bug in my code. Truly saying I still did not find  
> the bug . so I am writing now.

Try to use the  
DebugHelper([ActionView::Helpers::DebugHelper](http://api.rubyonrails.org/classes/ActionView/Helpers/DebugHelper.html))  
in your view to see the values. Maybe you forgot to set something.  
`
debug(blue_widget)
`

---

<div class="post-metadata">

**Author:** ![pgega](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ba9def/32.png) [@pgega](https://www.ruby-forum.com/u/pgega)\
**Post date:** [September 17, 2007, 1:25pm UTC](https://www.ruby-forum.com/t/looping-through-arrays-in-view/114678/3 "2007-09-17T13:25:31Z")

</div>

Great tool, but I did not forget about anything

Considering content output of Debug() , the record should work with  
following condition  
\<% if blue\_widget.B == 1 and blue\_widget.B == 1 %\>  
…some code

But works with  
\<% else %\>  
…code for rest cases

Maybe , I did something wrong with if/else conditional statements?

On Sep 17, 8:04 am, “Thomas W.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![pgega](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ba9def/32.png) [@pgega](https://www.ruby-forum.com/u/pgega)\
**Post date:** [September 17, 2007, 4:16pm UTC](https://www.ruby-forum.com/t/looping-through-arrays-in-view/114678/4 "2007-09-17T16:16:34Z")

</div>

Are you sure that the values are actually integers and not strings? Does  
this fix your problem?

blue\_widget.B.to\_i == 1 and blue\_widget.B.to\_i == 1

pgega wrote:

> > > Hi there ,
> 
> >

–  
Sincerely,

William P.

---

<div class="post-metadata">

**Author:** ![pgega](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ba9def/32.png) [@pgega](https://www.ruby-forum.com/u/pgega)\
**Post date:** [September 17, 2007, 7:44pm UTC](https://www.ruby-forum.com/t/looping-through-arrays-in-view/114678/5 "2007-09-17T19:44:07Z")

</div>

On Sep 17, 2007, at 12:02 AM, pgega wrote:

> \<% if blue\_widget.B == 1 and blue\_widget.B == 1 %\>  
> …some code  
> \<% if blue\_widget.a == 0 and blue.widget == 1 %\>

Are those the actual lines in your code, or typos from preparing your  
post?  
The first line is redundant, and the last line refers to a blue  
object, not a blue\_widget.
