Forum: Ruby on Rails Models, mixins, and acts_as

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.
7b2a4ea7a2c486b1b0ceab3c6d4680d9?d=identicon&s=25 Joe Cairns (diregnome)
on 2009-05-23 20:10
(Received via mailing list)
I'm having a little trouble with a mixin.  Here is the long and short, I
am
using a technique I found here:

http://redcorundum.blogspot.com/2006/06/mixing-in-...

To be able to mixin class and instance methods in the same module (works
great btw).  I'm using it to make a quick exporter for my models, where
I
can just mixin the module for the models where I need it.  Here's the
brief
version of the code:

# Class methods are declared in the "define_class_methods" method
> # the export function
> require 'mixin_class_methods'
>
> module Exporter
>
>   mixin_class_methods { |klass|
>   }
>
>   define_class_methods {


>     def export_object_name
>       self.to_s.downcase.pluralize
>     end
>
>     def export_column_names(columns_to_exclude=nil)
>        self.column_names
>     end
>   }
>  end



class Course < ActiveRecord::Base
>   include Exporter
>   acts_as_csv_exportable :default, self.export_column_names
> end


When I have it setup like this, it runs as expected.  However, I want to
DRY
things up and move all the export functionality into the module.  If I
comment out the  "acts_as_csv_exportable :default,
self.export_column_names"  line and move it to the mixin I get an
undefined
method name for "export_column_names".

Anyone have any ideas how to get around this?
This topic is locked and can not be replied to.