# Returning 'column' objects like content\_columns does

**URL:** <https://www.ruby-forum.com/t/returning-column-objects-like-content-columns-does/130524>\
**Category:** Rails\
**Created:** [February 29, 2008, 1:15am UTC](https://www.ruby-forum.com/t/returning-column-objects-like-content-columns-does/130524 "2008-02-29T01:15:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leonard\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/278dde/32.png) [@Leonard\_C](https://www.ruby-forum.com/u/Leonard_C)\
**Post date:** [February 29, 2008, 1:15am UTC](https://www.ruby-forum.com/t/returning-column-objects-like-content-columns-does/130524/1 "2008-02-29T01:15:21Z")

</div>

I’m working on my first rails project after having gone through quite a  
bit of Ruby on Rails/Up and Running.

I have a model ‘Configuration’.

In the view that got scaffolded for me (I’m still back on rails version  
1.2.3) I have a list.rhtml that looks like this

 \<% for column in Configuration.content\_columns %\> \<% end %\> 

\<% for configuration in @configurations %\>

  
\<% for column in Configuration.content\_columns %\>  
  
\<% end %\>

[snip …]

My Configuration table has many columns, and in the list view, I’d just  
like to show the ‘important’ columns. Initially in my model I defined

class Configuration \< ActiveRecord::Base  
def self.important\_columns  
return [:description, :rate, :duration, :host]  
end  
end

This didn’t work, but I realized I’m returning strings, not objects. I  
modified the view to be

\<% for column in Configuration.important\_columns %\>

  
\<% end %\>

But I now no longer have access to human\_name for the titles. How can I  
get access to the column objects, knowing their names?

I thought I could perhaps figure this out by myself if I could find the  
source code for content\_columns, but I couldn’t find it, any hints on  
how I might have accomplished that?

TIA,

Leonard

| \<%= column.human\_name %\> |
| --- |
| \<%=h configuration.send(column.name) %\> | \<%=h configuration.send(column) %\> |

---

<div class="post-metadata">

**Author:** ![Leonard\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/278dde/32.png) [@Leonard\_C](https://www.ruby-forum.com/u/Leonard_C)\
**Post date:** [February 29, 2008, 1:34am UTC](https://www.ruby-forum.com/t/returning-column-objects-like-content-columns-does/130524/2 "2008-02-29T01:34:42Z")

</div>

> I’m working on my first rails project after having gone through quite a bit of Ruby on Rails/Up and Running.

…

> But I now no longer have access to human\_name for the titles. How can I get access to the column objects, knowing their names?
> 
> I thought I could perhaps figure this out by myself if I could find the  
> source code for content\_columns, but I couldn’t find it, any hints on  
> how I might have accomplished that?

Look in the API docs for “content\_columns”. Then click the “source”  
link  
to see the method definition. For 1.2.5 it’s this:

```
  # File vendor/rails/activerecord/lib/active_record/base.rb, line 

```

781  
781: def content\_columns  
782: @content\_columns ||= columns.reject { |c| c.primary ||  
c.name =~ /(\_id|\_count)$/ || c.name == inheritance\_column }  
783: end
