Forum: Ruby on Rails how to get column_for_attribute?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
866edcb271e88be4bfd935eea7947730?d=identicon&s=25 Bojan Mihelac (Guest)
on 2006-01-30 23:09
(Received via mailing list)
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 Mihelac

--
Bojan Mihelac
Informatika Mihelac, Bojan Mihelac s.p.  |  www.informatikamihelac.com
-> tools, scripts, tricks from our code lab: http://source.mihelac.org
866edcb271e88be4bfd935eea7947730?d=identicon&s=25 Bojan Mihelac (Guest)
on 2006-01-31 19:29
(Received via mailing list)
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 Mihelac
Informatika Mihelac, Bojan Mihelac s.p.  |  www.informatikamihelac.com
-> tools, scripts, tricks from our code lab: http://source.mihelac.org
This topic is locked and can not be replied to.