# Access table names

**URL:** <https://www.ruby-forum.com/t/access-table-names/112736>\
**Category:** Rails\
**Created:** [August 22, 2007, 7:12pm UTC](https://www.ruby-forum.com/t/access-table-names/112736 "2007-08-22T19:12:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![smithy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a4c791/32.png) [@smithy](https://www.ruby-forum.com/u/smithy)\
**Post date:** [August 22, 2007, 7:12pm UTC](https://www.ruby-forum.com/t/access-table-names/112736/1 "2007-08-22T19:12:06Z")

</div>

Hello,  
Anyone know if there is a way to get all of the column names from the  
tables usinf rub on rails?  
Thanks again

---

<div class="post-metadata">

**Author:** ![smithy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a4c791/32.png) [@smithy](https://www.ruby-forum.com/u/smithy)\
**Post date:** [August 22, 2007, 7:38pm UTC](https://www.ruby-forum.com/t/access-table-names/112736/2 "2007-08-22T19:38:38Z")

</div>

Jack S. wrote:

> Hello,  
> Anyone know if there is a way to get all of the column names from the  
> tables usinf rub on rails?  
> Thanks again

yourModel.column\_names();

Returns an array of column names as strings.

---

<div class="post-metadata">

**Author:** ![smithy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a4c791/32.png) [@smithy](https://www.ruby-forum.com/u/smithy)\
**Post date:** [August 22, 2007, 7:47pm UTC](https://www.ruby-forum.com/t/access-table-names/112736/3 "2007-08-22T19:47:04Z")

</div>

Jack S. wrote:

> Hello,  
> Anyone know if there is a way to get all of the column names from the  
> tables usinf rub on rails?  
> Thanks again

For any table for which you have created a model, you can use the  
‘column\_names’ class method. eg.

class Person \< ActiveRecord::base  
end

columns = Person.column\_names  
=\>[“name”,“address”,“id”]
