# Simple question for processing array hash

**URL:** <https://www.ruby-forum.com/t/simple-question-for-processing-array-hash/146568>\
**Category:** Rails\
**Created:** [August 22, 2008, 1:29pm UTC](https://www.ruby-forum.com/t/simple-question-for-processing-array-hash/146568 "2008-08-22T13:29:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![predhme](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e8c25b/32.png) [@predhme](https://www.ruby-forum.com/u/predhme)\
**Post date:** [August 22, 2008, 1:29pm UTC](https://www.ruby-forum.com/t/simple-question-for-processing-array-hash/146568/1 "2008-08-22T13:29:24Z")

</div>

Hey guys/gals

I have three models…

Request  
Problem  
AgendaItem

the request and problem are setup as  
has\_one :agenda\_item, :as =\> :resource

and the AgendaItem is setup as  
belongs\_to :resource, :polymorphic =\> true

So basically I can define an agenda item as either a request or  
problem with the class name stored in resource\_type and the id stored  
in resource\_id in the AgendaItem table…

Each item is for a specific “group”. So item 1 maybe for IT and item 2  
may be for DB etc etc…

So here comes the question…

I need to construct a view that breaks down  
AgendaItem.find\_all\_by\_show(true) by group and by resource\_type… I  
feel that creating two array for each group (both resource types) is a  
bit much… Is there an easier way to itterate through the array by  
group in my view or something?

---

<div class="post-metadata">

**Author:** ![predhme](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e8c25b/32.png) [@predhme](https://www.ruby-forum.com/u/predhme)\
**Post date:** [August 22, 2008, 2:42pm UTC](https://www.ruby-forum.com/t/simple-question-for-processing-array-hash/146568/2 "2008-08-22T14:42:03Z")

</div>

On 22 Aug 2008, at 12:28, predhme wrote:

> So here comes the question…
> 
> I need to construct a view that breaks down  
> AgendaItem.find\_all\_by\_show(true) by group and by resource\_type… I  
> feel that creating two array for each group (both resource types) is a  
> bit much… Is there an easier way to itterate through the array by  
> group in my view or something?

I’d say that unless you’ve actually done it and it is performing  
unacceptably that you’re probably just worrying over an unimportant  
detail.

Fred

---

<div class="post-metadata">

**Author:** ![predhme](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e8c25b/32.png) [@predhme](https://www.ruby-forum.com/u/predhme)\
**Post date:** [August 22, 2008, 5:15pm UTC](https://www.ruby-forum.com/t/simple-question-for-processing-array-hash/146568/3 "2008-08-22T17:15:13Z")

</div>

Well we have 7 groups so id be constructing 14 arrays. Plus it would  
be nice to know for instances when “performance” need to be optimized.

On Aug 22, 8:41 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![predhme](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e8c25b/32.png) [@predhme](https://www.ruby-forum.com/u/predhme)\
**Post date:** [August 22, 2008, 5:25pm UTC](https://www.ruby-forum.com/t/simple-question-for-processing-array-hash/146568/4 "2008-08-22T17:25:48Z")

</div>

On 22 Aug 2008, at 16:14, predhme wrote:

> Well we have 7 groups so id be constructing 14 arrays. Plus it would  
> be nice to know for instances when “performance” need to be optimized.

On a multi gigahertz machine with gigs of ram 14 arrays is hardly  
going to matter. rails creates and dumps thousands more without you  
even noticing.  
If you can give a more concrete example of what you’re doing someone  
might be able to help.

Fred
