# Looping through arrays in View  ?

**URL:** <https://discuss.rubyonrails.org/t/looping-through-arrays-in-view/18235>\
**Category:** rubyonrails-talk\
**Created:** [September 17, 2007, 6:02am UTC](https://discuss.rubyonrails.org/t/looping-through-arrays-in-view/18235 "2007-09-17T06:02:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pgega](https://avatars.discourse-cdn.com/v4/letter/p/ba9def/32.png) [@pgega](https://discuss.rubyonrails.org/u/pgega)\
**Post date:** [September 17, 2007, 6:02am UTC](https://discuss.rubyonrails.org/t/looping-through-arrays-in-view/18235/1 "2007-09-17T06:02:47Z")

</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 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% if blue\_widget.a == 0 and blue.widget == 1 %\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...come code for second condition &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% 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:** ![Thomas\_Wieczorek](https://avatars.discourse-cdn.com/v4/letter/t/e47c2d/32.png) [@Thomas\_Wieczorek](https://discuss.rubyonrails.org/u/Thomas_Wieczorek)\
**Post date:** [September 17, 2007, 7:04am UTC](https://discuss.rubyonrails.org/t/looping-through-arrays-in-view/18235/2 "2007-09-17T07:04:48Z")

</div>

Try to use the DebugHelper([http://api.rubyonrails.org/classes/ActionView/Helpers/DebugHelper.html](http://api.rubyonrails.org/classes/ActionView/Helpers/DebugHelper.html)) in your view to see the values. Maybe you forgot to set something. \<code\> &nbsp;&nbsp;debug(blue\_widget) \</code\>

---

<div class="post-metadata">

**Author:** ![pgega](https://avatars.discourse-cdn.com/v4/letter/p/ba9def/32.png) [@pgega](https://discuss.rubyonrails.org/u/pgega)\
**Post date:** [September 17, 2007, 7:40am UTC](https://discuss.rubyonrails.org/t/looping-through-arrays-in-view/18235/3 "2007-09-17T07:40:20Z")

</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?

---

<div class="post-metadata">

**Author:** ![William\_Pratt](https://avatars.discourse-cdn.com/v4/letter/w/9dc877/32.png) [@William\_Pratt](https://discuss.rubyonrails.org/u/William_Pratt)\
**Post date:** [September 17, 2007, 2:15pm UTC](https://discuss.rubyonrails.org/t/looping-through-arrays-in-view/18235/4 "2007-09-17T14:15:18Z")

</div>

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

```ruby
blue_widget.B.to_i == 1 and blue_widget.B.to_i == 1

```

pgega wrote:

---

<div class="post-metadata">

**Author:** ![George\_Bailey](https://avatars.discourse-cdn.com/v4/letter/g/9d8465/32.png) [@George\_Bailey](https://discuss.rubyonrails.org/u/George_Bailey)\
**Post date:** [September 17, 2007, 5:42pm UTC](https://discuss.rubyonrails.org/t/looping-through-arrays-in-view/18235/5 "2007-09-17T17:42:46Z")

</div>

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.
