views:

954

answers:

2

Hi all,

I'd like to run a rake task in my controller. Is there any way to do this?

Thanks,

Sophy,

A: 

Here's a couple of ways.

Simone Carletti
+6  A: 

I don't find it good style to call a rake task in code. I recommend putting the code for the task that you want to execute somewhere outside a rake task, and have the rake task call this code.

This not only has the advantage of being easy to call outside rake (which is what you want), but it also makes it much easier to test the rake task.

ddfreyne
+1 I concur: this is a perfect example of things that should be refactored and called in two different ways.
James A. Rosen