开发者

Provide parameter for rake in ruby

开发者 https://www.devze.com 2023-02-11 00:40 出处:网络
I have a rake task that uses a parameter on the command line like that: rake sunspot:reindex[, MyModel]

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?


You probably need to use invoke instead of execute:

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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消