1

I have a rake task that uses a parameter on the command line like that:

rake sunspot:reindex[, MyModel]

(Yes, the direct comma behind the bracket is correct.)

How do I specify the same rake command from within Ruby?

Some attempts that don't work:

Rake::Task['sunspot:reindex'].execute("[, ActsAsTaggableOn::Tagging]")
Rake::Task['sunspot:reindex'].execute([nil, ActsAsTaggableOn::Tagging])
Rake::Task['sunspot:reindex[, ActsAsTaggableOn::Tagging]'].execute

Some other suggestions what I could try else?

Zardoz
  • 15,245
  • 21
  • 84
  • 130

2 Answers2

1

You probably need to use invoke instead of execute:

Rake::Task['sunspot:reindex'].invoke(nil, ActsAsTaggableOn::Tagging)
Yossi
  • 11,378
  • 2
  • 49
  • 61
  • Thanks. I also found this nice answer: http://stackoverflow.com/questions/825748/how-do-i-pass-command-line-arguments-to-a-rake-task/825832#825832 – Zardoz Feb 16 '11 at 13:01
0

You can invoke the command as a system process. You have several alternatives

klass = Model

`rake sunspot:reindex #{klass}`
%x(rake sunspot:reindex #{klass})
system "rake", "sunspot:reindex", klass
Simone Carletti
  • 168,884
  • 43
  • 353
  • 360
  • Yes, I know. But what I would like to find out is how to set parameters by using Rake::Task ... I am just curious. – Zardoz Feb 16 '11 at 12:43