0

I have the following rake task:

update_rank.rake

task :build => :environment do
  Result.desc(:score).each_with_index do |result, position|
    result.update_attribute(:rank, position + 1)
  end
end

I want to call this task from the controller whenever a result is created. What is the best way to do this? Should i instead move this task into a model?

Jeremy Lynch
  • 6,780
  • 3
  • 52
  • 63
  • http://stackoverflow.com/questions/1170148/run-rake-task-in-controller –  Aug 16 '13 at 16:44
  • 1
    Search for background task gems like `delayed_job`. What you're describing is an asynchronous process with a queue trigger. There are several such libraries already built and ready to use. – jdl Aug 16 '13 at 16:44

0 Answers0