# How to get column\_for\_attribute?

**URL:** <https://www.ruby-forum.com/t/how-to-get-column-for-attribute/99093>\
**Category:** Rails\
**Created:** [January 30, 2006, 11:09pm UTC](https://www.ruby-forum.com/t/how-to-get-column-for-attribute/99093 "2006-01-30T23:09:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmihelac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5fc32e/32.png) [@bmihelac](https://www.ruby-forum.com/u/bmihelac)\
**Post date:** [January 30, 2006, 11:09pm UTC](https://www.ruby-forum.com/t/how-to-get-column-for-attribute/99093/1 "2006-01-30T23:09:02Z")

</div>

Hi all,  
In the code below I don’t understand:

1. Why I have to prepend overriden method content\_columns with “self.”  
to get it working?
2. Why column\_for\_attribute method is not working (no such method?) even  
if SomeTable is subclass of ActiveRecord::Base which have public  
column\_for\_attribute method?

> class SomeTable \< ActiveRecord::Base
> 
> def self.content\_columns  
> column = column\_for\_attribute(‘sometable\_id’)  
> super  
> end  
> end  
> Any help is appreciated.  
> Bojan M.

–  
Bojan M.  
Informatika Mihelac, Bojan M. s.p. | [www.informatikamihelac.com](http://www.informatikamihelac.com)  
 → tools, scripts, tricks from our code lab: [http://source.mihelac.org](http://source.mihelac.org)

---

<div class="post-metadata">

**Author:** ![bmihelac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5fc32e/32.png) [@bmihelac](https://www.ruby-forum.com/u/bmihelac)\
**Post date:** [January 31, 2006, 7:29pm UTC](https://www.ruby-forum.com/t/how-to-get-column-for-attribute/99093/2 "2006-01-31T19:29:37Z")

</div>

I am come with these conclusions so far, please :

> 1. Why I have to prepend overriden method content\_columns with “self.”  
> to get it working?  
> ‘content\_columns’ is class method of ActiveRecord::Base, so it should be  
> defined as:  
> def Base.content\_columns  
> if we want to override it, right?
> 2. Why column\_for\_attribute method is not working (no such method?)  
> even if SomeTable is subclass of ActiveRecord::Base which have public  
> column\_for\_attribute method?  
> ‘content\_columns’ is a class method and cannot call  
> ‘column\_for\_attribute’ which is object method, right?  
> However, this would work:  
> column = columns\_hash[‘sometable\_id’]  
> And original example:
> 
> > class SomeTable \< ActiveRecord::Base
> > 
> > def self.content\_columns  
> > column = column\_for\_attribute(‘sometable\_id’)  
> > super  
> > end  
> > end

–  
Bojan M.  
Informatika Mihelac, Bojan M. s.p. | [www.informatikamihelac.com](http://www.informatikamihelac.com)  
 → tools, scripts, tricks from our code lab: [http://source.mihelac.org](http://source.mihelac.org)
