Jan wrote:
I want to define my own Content_colums methode as part of the ActiveRecord::Base class.
To do so, I have added the following code:
[Environment.rb] require 'model_extensions' ActiveRecord::Base.send(:extend, ModelExtensions)
[model_extensions.rb] module ModelExtensions #Define Mixins for the ActiveRecord::Base modelclass # Define list of available items for select def valid_items(current_item=nil) #.... works fine end
# Overwrite displayble columns attribute, eliminate: created_* and updated_* def content_columns @content_columns ||= columns.reject { |c| c.primary || c.name =~ /(_id|_count)$/ || c.name == inheritance_column || c.name == locking_column || c.name =~ /(created_|updated_)/} end end
However, this won't work for the content_columns! The valid_items method though works perfectly as it is added to the AR:Base class. But overwriting content_columns has no effect at all. I tried to put 'attr :content_columns, true' but no effect neither
extend will only add methods, not re-define existing ones.
Instead, just write model_extensions.rb as
class ActiveRecord::Base def self.valid_items(current_item=nil) ... end
def self.content_columns ... end end
and require this in environment.rb