# How to use rake command in Rails application

**URL:** <https://www.ruby-forum.com/t/how-to-use-rake-command-in-rails-application/155382>\
**Category:** Rails\
**Created:** [December 11, 2008, 9:03am UTC](https://www.ruby-forum.com/t/how-to-use-rake-command-in-rails-application/155382 "2008-12-11T09:03:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hema\_mca](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/779978/32.png) [@hema\_mca](https://www.ruby-forum.com/u/hema_mca)\
**Post date:** [December 11, 2008, 9:03am UTC](https://www.ruby-forum.com/t/how-to-use-rake-command-in-rails-application/155382/1 "2008-12-11T09:03:53Z")

</div>

Hi,

```
I want to clear my logs files when they are exceeding certain limit 

```

of  
memory  
The size of the files can be determined by using the File.size() and  
I  
can clear the log files using the rake log:clear command  
But this has to be done through my application  
where i will create a method when the user clicks the logout button  
then  
the method checks the log files and if the files occupied more memory  
then  
it automatically refreshes the contents…  
Please help me how to achieve my requirement

Thanks

---

<div class="post-metadata">

**Author:** ![hema\_mca](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/779978/32.png) [@hema\_mca](https://www.ruby-forum.com/u/hema_mca)\
**Post date:** [December 14, 2008, 8:41pm UTC](https://www.ruby-forum.com/t/how-to-use-rake-command-in-rails-application/155382/2 "2008-12-14T20:41:45Z")

</div>

Hema G. wrote:

> Hi,
> 
> ```
> I want to clear my logs files when they are exceeding certain limit 
> 
> ```
> 
> of  
> memory  
> The size of the files can be determined by using the File.size() and  
> I  
> can clear the log files using the rake log:clear command  
> But this has to be done through my application  
> where i will create a method when the user clicks the logout button  
> then  
> the method checks the log files and if the files occupied more memory  
> then  
> it automatically refreshes the contents…  
> Please help me how to achieve my requirement
> 
> Thanks

I think this will work:

Rake::Task[‘log:clear’].invoke

---

<div class="post-metadata">

**Author:** ![hema\_mca](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/779978/32.png) [@hema\_mca](https://www.ruby-forum.com/u/hema_mca)\
**Post date:** [January 12, 2009, 8:13am UTC](https://www.ruby-forum.com/t/how-to-use-rake-command-in-rails-application/155382/3 "2009-01-12T08:13:20Z")

</div>

Thank You  
But where I have to write the line Rake::Task[‘log:clear’].invoke  
It is throwing exception as RAKE uninitialised constant…

On Dec 15 2008, 12:41 am, Jeremy Weiskotten \<rails-mailing-

---

<div class="post-metadata">

**Author:** ![hema\_mca](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/779978/32.png) [@hema\_mca](https://www.ruby-forum.com/u/hema_mca)\
**Post date:** [January 12, 2009, 10:28am UTC](https://www.ruby-forum.com/t/how-to-use-rake-command-in-rails-application/155382/4 "2009-01-12T10:28:56Z")

</div>

edit: if it still fails, try something like this:  
require ‘rake’  
require ‘rake/testtask’  
require ‘rake/rdoctask’  
require ‘tasks/rails’

after that, this should work  
Rake::Task[‘taskname’].invoke

---

<div class="post-metadata">

**Author:** ![hema\_mca](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/779978/32.png) [@hema\_mca](https://www.ruby-forum.com/u/hema_mca)\
**Post date:** [January 12, 2009, 10:04am UTC](https://www.ruby-forum.com/t/how-to-use-rake-command-in-rails-application/155382/5 "2009-01-12T10:04:46Z")

</div>

i guess this should work form anywhere. but pay attention: “RAKE” (all  
capitals) is expected to be a constant.

---

<div class="post-metadata">

**Author:** ![hema\_mca](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/779978/32.png) [@hema\_mca](https://www.ruby-forum.com/u/hema_mca)\
**Post date:** [January 20, 2009, 10:51am UTC](https://www.ruby-forum.com/t/how-to-use-rake-command-in-rails-application/155382/6 "2009-01-20T10:51:45Z")

</div>

Great…  
Thanks a lot…  
It is working Fine… thank you very much
