# Models, mixins, and acts\_as

**URL:** <https://www.ruby-forum.com/t/models-mixins-and-acts-as/168670>\
**Category:** Rails\
**Created:** [May 23, 2009, 8:10pm UTC](https://www.ruby-forum.com/t/models-mixins-and-acts-as/168670 "2009-05-23T20:10:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcernelli](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/73ab20/32.png) [@jcernelli](https://www.ruby-forum.com/u/jcernelli)\
**Post date:** [May 23, 2009, 8:10pm UTC](https://www.ruby-forum.com/t/models-mixins-and-acts-as/168670/1 "2009-05-23T20:10:41Z")

</div>

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-class-methods.html](http://redcorundum.blogspot.com/2006/06/mixing-in-class-methods.html)

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?
