Thor 脚本 ruby​​ 中的 Rake 任务

发布于 2024-10-10 11:10:45 字数 157 浏览 0 评论 0原文

我正在构建一个安装程序。 有了这个,我想以某种方式迁移数据库。 我正在使用 Thor 在 Rails 3 中制作安装程序。

所以类似(在命令行中)

rake db:create
rake db:migrate

谢谢。

i'm in the process of building an installer.
And with that, i want to migrate the database somehow.
I'm making my installer in Rails 3 using Thor.

So something like(in the command line)

rake db:create
rake db:migrate

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱殇璃 2024-10-17 11:10:45

Rails Generator api实际上提供了一个rake方法,并且非常容易使用。例如,您的生成器文件可能如下所示:

class RakeTestGenerator < Rails::Generators::Base
  source_root File.expand_path('../templates', __FILE__)

  def rake_db
    rake("db:migrate")
  end
end

然后,您可以通过运行以下命令在 Rails 应用程序中执行此文件。

rails g rake_test

这相当于在命令行中运行“rake db:migrate”。请注意,rails 生成器中的所有公共定义的方法都会在命令运行时执行。

其他信息: rake 方法由 Rails::Generators::Actions 模块提供,并可通过 Rails::Generators::Base 类使用。有关更多信息,请参阅官方文档

The rails generator api actually provides a rake method, and is very easy to use. So for example your generator file could look like:

class RakeTestGenerator < Rails::Generators::Base
  source_root File.expand_path('../templates', __FILE__)

  def rake_db
    rake("db:migrate")
  end
end

You could then execute this within your rails app by running the following.

rails g rake_test

Which would be the equivalent of running "rake db:migrate" in the command line. Note that all publicly defined methods in a rails generator are executed when the command is run.

Additional info: The rake method is provided by Rails::Generators::Actions module and is available by the Rails::Generators::Base class. See the Official Documentation for more information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文