# Required file for rake task -- put into a plugin?

**URL:** <https://www.ruby-forum.com/t/required-file-for-rake-task-put-into-a-plugin/78423>\
**Category:** Rails\
**Created:** [December 5, 2006, 6:03pm UTC](https://www.ruby-forum.com/t/required-file-for-rake-task-put-into-a-plugin/78423 "2006-12-05T18:03:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ratchetcat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ratchetcat](https://www.ruby-forum.com/u/ratchetcat)\
**Post date:** [December 5, 2006, 6:03pm UTC](https://www.ruby-forum.com/t/required-file-for-rake-task-put-into-a-plugin/78423/1 "2006-12-05T18:03:20Z")

</div>

Hello all. I’ve just written up a bit of ruby code that I’d like to use  
in a rake task for my web application (it has to be run on a schedule,  
and calling rake through cron seems to be a good way to do that).

My question is: Where should I place this code so that it’s both  
accessible to the rake task and logically located in the rails  
application directory structure?

I could place it into a plugin. However, I don’t feel entirely  
comfortable with that approach since this functionality is pretty  
important to the application. It’s not really something that should be  
tacked on.

I could also place the code into the lib/tasks directory. However, that  
seems rather messy.

Where would you put it? Thanks for any suggestions or insight.

---

<div class="post-metadata">

**Author:** ![ratchetcat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ratchetcat](https://www.ruby-forum.com/u/ratchetcat)\
**Post date:** [December 5, 2006, 7:10pm UTC](https://www.ruby-forum.com/t/required-file-for-rake-task-put-into-a-plugin/78423/2 "2006-12-05T19:10:17Z")

</div>

Hello Jon,

2006/12/5, Jon F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I could also place the code into the lib/tasks directory. However, that  
> seems rather messy.

Why do you think it’s messy ? That’s where Rake tasks are supposed to  
go.

Simply name your file “lib/tasks/mytasks.rake” and go from there.

## Bye !

FranÃ§ois Beausoleil  
[http://blog.teksol.info/](http://blog.teksol.info/)  
[http://piston.rubyforge.org/](http://piston.rubyforge.org/)

---

<div class="post-metadata">

**Author:** ![ratchetcat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ratchetcat](https://www.ruby-forum.com/u/ratchetcat)\
**Post date:** [December 5, 2006, 8:15pm UTC](https://www.ruby-forum.com/t/required-file-for-rake-task-put-into-a-plugin/78423/3 "2006-12-05T20:15:23Z")

</div>

Thanks, FranÃ§ois!

I have no problem putting the rake file in the lib/tasks directory. I’m  
just curious whether I should also put my library file (containing  
objects I use in the rake task) in the same place. It just struck me as  
a little messy to put it in the same directory as the rake task files.

---

<div class="post-metadata">

**Author:** ![ratchetcat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ratchetcat](https://www.ruby-forum.com/u/ratchetcat)\
**Post date:** [December 5, 2006, 9:04pm UTC](https://www.ruby-forum.com/t/required-file-for-rake-task-put-into-a-plugin/78423/4 "2006-12-05T21:04:33Z")

</div>

Hello Jon,

2006/12/5, Jon F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Okay, I went googling around the web and ran across at least one example  
> of libraries being placed in – you guessed it – the lib directory.  
> That seems to work correctly for rake and the application controllers.  
> It also doesn’t offend my rails-powered sense of ‘rightness’.

I realize now that I misread your original E-Mail. You wanted to have  
some utility code available for the Rake task, but not necessarily for  
the rest of the application. Now that I understand your requirement,  
I guess I would simply have dropped the code in the task file.  
Simple, effective.

## Bye !

FranÃ§ois Beausoleil  
[http://blog.teksol.info/](http://blog.teksol.info/)  
[http://piston.rubyforge.org/](http://piston.rubyforge.org/)

---

<div class="post-metadata">

**Author:** ![ratchetcat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ratchetcat](https://www.ruby-forum.com/u/ratchetcat)\
**Post date:** [December 5, 2006, 8:52pm UTC](https://www.ruby-forum.com/t/required-file-for-rake-task-put-into-a-plugin/78423/5 "2006-12-05T20:52:39Z")

</div>

Okay, I went googling around the web and ran across at least one example  
of libraries being placed in – you guessed it – the lib directory.  
That seems to work correctly for rake and the application controllers.  
It also doesn’t offend my rails-powered sense of ‘rightness’.

( Ah, so obvious… )

Thanks!
