简体   繁体   English

Rails启动期间如何运行rake任务?

[英]How to run rake task during rails initiation?

I have my own secret key generating script that I've placed in a rake command. 我有自己的secret key生成脚本,该脚本已放置在rake命令中。 I can execute this on its own without starting the rails server , but I want to incorporate this rake task into the rails server initiation so I don't need to call the rake task by itself anymore. 我可以自行执行此操作而无需启动rails server ,但是我想将此rake任务合并到rails server启动中,因此不再需要rake调用rake任务。

Where/How do I run this rake command such that it's part of the initiation process? 在哪里/如何运行此rake命令,使其成为启动过程的一部分?

If the secret key rake task doesn't have the environment dependency, you can just create a new initializer in config/initializers and name it secret_generate.rb for example, and in it write: 如果secret key耙任务不依赖于environment ,则可以在config/initializers创建一个新的初始化config/initializers并将其命名为secret_generate.rb ,例如:

`rake your_task_name`

This will run your rake task on rails server initiation. 这将在Rails服务器启动时运行rake任务。

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

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