# Retrieving all values of the column from the table

**URL:** <https://www.ruby-forum.com/t/retrieving-all-values-of-the-column-from-the-table/162053>\
**Category:** Rails\
**Created:** [March 5, 2009, 10:27am UTC](https://www.ruby-forum.com/t/retrieving-all-values-of-the-column-from-the-table/162053 "2009-03-05T10:27:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 5, 2009, 10:27am UTC](https://www.ruby-forum.com/t/retrieving-all-values-of-the-column-from-the-table/162053/1 "2009-03-05T10:27:22Z")

</div>

Hi,

## I have a function in my model like

## class Pattern def self.get\_all(field) @patterns = Pattern.find(:all) @patterns.collect do |pp| pp.field end end end

so that whatever field i give to the function,  
it returns all the column values in an Array

I dont know whether i am doing it right or not  
Any suggestions

Thanx,  
Vimal Das

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 5, 2009, 10:45am UTC](https://www.ruby-forum.com/t/retrieving-all-values-of-the-column-from-the-table/162053/2 "2009-03-05T10:45:37Z")

</div>

On Mar 5, 9:26 am, vimal [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I dont know whether i am doing it right or not

Well, have you tried it ? (look up the send method)

Fred

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 5, 2009, 11:40am UTC](https://www.ruby-forum.com/t/retrieving-all-values-of-the-column-from-the-table/162053/3 "2009-03-05T11:40:53Z")

</div>

I tried it Fred,but it didn’t work

Instead this did the job for me

class Pattern  
def self.get\_all(field)  
@patterns = Pattern.find(:all)  
@patterns.collect do |pp|  
pp[field]  
end  
end  
end

Regards,  
Vimal Das
