What I want to do:
In a model.rb, in after_commit, I want to run rake task ts:reindex
ts:reindex is normally run with a rake ts:index
I had this same issue and couldn't get the accepted answer to work in my controller with a Rails 4 project due to a load file error. This post gave me a working solution:
def restart_search
require 'rake'
spec = Gem::Specification.find_by_name 'thinking-sphinx'
load "#{spec.gem_dir}/lib/thinking_sphinx/tasks.rb"
Rake::Task["ts:stop"].execute
Rake::Task["ts:start"].execute
respond_to do |format|
format.js { head :ok }
end
end