Forum: Ruby on Rails Calling Rake from INSIDE the application

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
87d23bad096ab9696c1b945de6e5c0d7?d=identicon&s=25 Dante Regis (Guest)
on 2008-12-02 03:53
(Received via mailing list)
Hey there
I would like to know if I can call a rake task from inside my Rails App.
Something like

class MyModel < ActiveRecord::Base
  after_save :run_task

  def run_task"my:little:task")

This is the deal: I use thinking-sphinx and need to update a bunch of
through Model.update_all. But I would like sphinx to index it just after
done, by running rake ts:index.

Is that possible?

4c438a80fc30661ad619ea177cf9cbd0?d=identicon&s=25 Freddy Andersen (Guest)
on 2008-12-02 08:44
(Received via mailing list)
def run_task
  result = %x(rake #{params[:rake_task]})

If you don't want to hold the thread you can install the crontab gem
and install a new crontab with a ts:in or use background-fu and push
the job to the background...
This topic is locked and can not be replied to.