# Using module methods in Rake task& model?

**URL:** <https://discuss.rubyonrails.org/t/using-module-methods-in-rake-task-model/41600>\
**Category:** rubyonrails-talk\
**Created:** [April 15, 2009, 10:46pm UTC](https://discuss.rubyonrails.org/t/using-module-methods-in-rake-task-model/41600 "2009-04-15T22:46:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [April 15, 2009, 10:46pm UTC](https://discuss.rubyonrails.org/t/using-module-methods-in-rake-task-model/41600/1 "2009-04-15T22:46:40Z")

</div>

Hello,

I'm trying to use some methods I'm defining in a module in a model and my rake task. How can I do this? Any help would be appreciated.

I've currently got the following, but my rake task can't access the methods in my module. Instead, I get..

undefined local variable or method `report\_csv\_process' for #\<Object:0x284f9e8\>

/lib/module/order\_process module order\_process &nbsp;&nbsp;def process\_order(id) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#do stuff &nbsp;&nbsp;end

/lib/tasks/ordering.rake

include order\_process namespace :send\_report do &nbsp;&nbsp;task :order =\> :environment do &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;process\_order(id) &nbsp;&nbsp;end end

/app/models/segment.rb class Segment \< ActiveRecord::Base &nbsp;&nbsp;include report\_csv\_process

&nbsp;&nbsp;&nbsp;bla bla

end

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [April 16, 2009, 12:06am UTC](https://discuss.rubyonrails.org/t/using-module-methods-in-rake-task-model/41600/2 "2009-04-16T00:06:14Z")

</div>

I was a little off, but still haven't quite figured it out. I currently have:

> /lib/module/order\_process.rb module order\_process &nbsp;&nbsp;def process\_order(id) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#do stuff &nbsp;&nbsp;end
> 
> /lib/tasks/ordering.rake
> 
> include 'order\_process.rb' namespace :send\_report do &nbsp;&nbsp;task :order =\> :environment do &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;process\_order(id) &nbsp;&nbsp;end end
> 
> /app/models/segment.rb class Segment \< ActiveRecord::Base &nbsp;&nbsp;include 'report\_csv\_process.rb'
> 
> &nbsp;&nbsp;&nbsp;bla bla
> 
> end

I tried removing the single quotes, without luck

---

<div class="post-metadata">

**Author:** ![Dave12](https://avatars.discourse-cdn.com/v4/letter/d/9e8a1a/32.png) [@Dave12](https://discuss.rubyonrails.org/u/Dave12)\
**Post date:** [May 3, 2009, 11:19pm UTC](https://discuss.rubyonrails.org/t/using-module-methods-in-rake-task-model/41600/3 "2009-05-03T23:19:58Z")

</div>

Did you ever figure out how this is done? I'm stuck on the exact problem (trying to use some custom module code inside a rake task).

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [May 4, 2009, 1:47pm UTC](https://discuss.rubyonrails.org/t/using-module-methods-in-rake-task-model/41600/4 "2009-05-04T13:47:01Z")

</div>

Hu? Did you not read my last post? You wrote almost exactly the same questing twice. You have to both require the file, then include the module.

###rake\_file.rb require 'lib/modules/your\_module\_filename.rb'

namespace :your\_rake\_task do &nbsp;&nbsp;include your\_module\_name

&nbsp;&nbsp;#do stuff end
