# Running through results of find()

**URL:** <https://www.ruby-forum.com/t/running-through-results-of-find/57829>\
**Category:** Rails\
**Created:** [April 14, 2006, 4:33pm UTC](https://www.ruby-forum.com/t/running-through-results-of-find/57829 "2006-04-14T16:33:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![S-redyck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@S-redyck](https://www.ruby-forum.com/u/S-redyck)\
**Post date:** [April 14, 2006, 4:33pm UTC](https://www.ruby-forum.com/t/running-through-results-of-find/57829/1 "2006-04-14T16:33:33Z")

</div>

Hi,

I’ve got a question about the find() method in RoR

This is my code:  
actions=Action.find(:all, :conditions =\> “ActivityID=‘actid’”)

This should return a list, array, hash, … ? of Actions.  
What type of data does find() return? And how do I run through it?

I would like to show Action.ActionCode for every action in actions.

I tried:  
for action in actions  
output += action.ActionCode  
end

Didn’t work.

Thanks,

Steven.

---

<div class="post-metadata">

**Author:** ![S-redyck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@S-redyck](https://www.ruby-forum.com/u/S-redyck)\
**Post date:** [April 14, 2006, 4:37pm UTC](https://www.ruby-forum.com/t/running-through-results-of-find/57829/2 "2006-04-14T16:37:52Z")

</div>

Um, this seems to be a question of understanding Ruby the programming  
language rather than understanding Rails the framework.

#find returns an Array object. There are many ways to iterate through an  
array, you should check the Ruby documentation here:  
[http://www.ruby-doc.org/core/](http://www.ruby-doc.org/core/)

Steven De Ryck wrote:

> I would like to show Action.ActionCode for every action in actions.  
> Steven.

–  
Sau S.

[http://blog.saush.com](http://blog.saush.com)  
[http://read.saush.com](http://read.saush.com)  
[http://jaccal.sourceforge.net](http://jaccal.sourceforge.net)

---

<div class="post-metadata">

**Author:** ![S-redyck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@S-redyck](https://www.ruby-forum.com/u/S-redyck)\
**Post date:** [April 14, 2006, 11:18pm UTC](https://www.ruby-forum.com/t/running-through-results-of-find/57829/3 "2006-04-14T23:18:01Z")

</div>

On Apr 14, 2006, at 11:51 AM, Chris T wrote:

> It returns an array of hashes. Try going into the console (ruby  
> script/console) and doing your

No, it’ll return an array of Action objects. Assuming Action is an  
ActiveRecord subclass, it’s  
definitely NOT a hash.

–  
– Tom M.

---

<div class="post-metadata">

**Author:** ![S-redyck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@S-redyck](https://www.ruby-forum.com/u/S-redyck)\
**Post date:** [April 15, 2006, 12:31am UTC](https://www.ruby-forum.com/t/running-through-results-of-find/57829/4 "2006-04-15T00:31:39Z")

</div>

My bad. That’s what happens when a noob tries to help another noob ☹  
Thanks for clarifying.

---

<div class="post-metadata">

**Author:** ![S-redyck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@S-redyck](https://www.ruby-forum.com/u/S-redyck)\
**Post date:** [April 14, 2006, 8:55pm UTC](https://www.ruby-forum.com/t/running-through-results-of-find/57829/5 "2006-04-14T20:55:55Z")

</div>

It returns an array of hashes. Try going into the console (ruby  
script/console) and doing your

actions=Action.find(:all…)

and it’ll echo the resulting array.

By the way, action.ActionCode doesn’t look right – attributes are  
normally lower case.

Hope this helps

---

<div class="post-metadata">

**Author:** ![S-redyck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@S-redyck](https://www.ruby-forum.com/u/S-redyck)\
**Post date:** [April 15, 2006, 1:14am UTC](https://www.ruby-forum.com/t/running-through-results-of-find/57829/6 "2006-04-15T01:14:29Z")

</div>

No problem, just trying to be helpful.

Let me guess: You (like I) came from Perl? 🙂

There are _no_ built in types in Ruby, everything  
is an object. The question is, what type of object  
is it?

I only point this out because I see a lot of new  
users suggesting that most output from .inspect  
is displaying hashes, when they’re really looking  
at objects that are NOT hashes.

I’ve learned a lot by helping others on the list,  
and occasionally being wrong and getting corrected,  
so keep up the good work!

– -- Tom M.

---

<div class="post-metadata">

**Author:** ![S-redyck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@S-redyck](https://www.ruby-forum.com/u/S-redyck)\
**Post date:** [April 15, 2006, 9:33am UTC](https://www.ruby-forum.com/t/running-through-results-of-find/57829/7 "2006-04-15T09:33:24Z")

</div>

No, PHP. About 25% through the Pickaxe at the moment (and would  
recommend to all noobs that they take the time to read it – rails  
starts to make much more sense). Taking a bit of time for the whole OO  
thing to sink in, but actually I’m lovin it.
