Hi guys,
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
Any clues?
-- 
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---
Mark Reginald James
2006-Sep-11  09:53 UTC
Re: Overwriting ActiveRecord::Base.content_columns
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 neitherextend 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 -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---