简体   繁体   English

如何在Rails应用程序中调用rake脚本?

[英]How would I invoke a rake script inside my rails application?

I want to execute a rake script from within a model. 我想从模型中执行rake脚本。 Beside calling it via backtick, is there anyway to include the rake library and call Rake::Task['some_task'].invoke. 除了通过反引号调用它之外,还包括rake库并调用Rake :: Task ['some_task']。invoke。

I know this doesn't answer your question directly, but if it's shared code why not make it a module? 我知道这不能直接回答您的问题,但是如果它是共享代码,为什么不将其设为模块? You'd avoid duplication and be able to use it wherever you need to. 您将避免重复,并可以在任何需要的地方使用它。

您可以使用“系统”来运行它,但是我同意安迪的观点,应该共享它以避免重复

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM